[root@VM-4-16-centos ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
下载完成后是这样的:
[root@VM-4-16-centos ~]# cd /etc/yum.repos.d/ [root@VM-4-16-centos yum.repos.d]# ls CentOS-Base.repo CentOS-Epel.repo
可以看到没有MySql的repo
[root@VM-4-16-centos ~]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm 警告:mysql57-community-release-el7-9.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql57-community-release-el7-9 ################################# [100%] [root@VM-4-16-centos ~]# cd - [root@VM-4-16-centos yum.repos.d]# ls CentOS-Base.repo CentOS-Epel.repo mysql-community.repo mysql-community-source.repo
[root@VM-4-16-centos yum.repos.d]# rpm -qa | grep mysql mysql57-community-release-el7-9.noarch
可以看到只有我们刚才安装的包,没有其他的mysql包
[root@VM-4-16-centos ~]# yum install -y mysql-server
执行命令后,正常下载即可,但是下载完后会有个告警
失败的软件包是:mysql-community-libs-compat-5.7.37-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
处理办法:修改 /etc/yum.repos.d/mysql-community.repo,找到你安装的MySql版本。修改其中的gpgcheck=0
即可,默认值为1
[root@VM-4-16-centos yum.repos.d]# vim /etc/yum.repos.d/mysql-community.repo
修改前:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
修改后:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# 启动mMysql [root@VM-4-16-centos yum.repos.d]# systemctl start mysqld # 查看启动状态 [root@VM-4-16-centos ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 六 2022-03-19 18:56:11 CST; 28min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 17643 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 17579 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 17647 (mysqld) CGroup: /system.slice/mysqld.service └─17647 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 3月 19 18:56:06 VM-4-16-centos systemd[1]: Starting MySQL Server... 3月 19 18:56:11 VM-4-16-centos systemd[1]: Started MySQL Server.
runing表示已经启动
[root@VM-4-16-centos ~]# mysql -V mysql Ver 14.14 Distrib 5.7.37, for Linux (x86_64) using EditLine wrapper
[root@VM-4-16-centos ~]# vim /etc/my.cnf
通过my.cnf文件找到log-error=/var/log/mysqld.log文件,在改文件中根据password关键字查询初始密码
[root@VM-4-16-centos ~]# grep "password" /var/log/mysqld.log
找到初始密码之后,就可以开始登录了
[root@VM-4-16-centos ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.37 Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Enter password: 这里输入密码即可,出现mysql>表示已经登录成功
mysql> alter user 'root'@'localhost' identified by "xxxxxx";
xxxxxx表示需要修改的密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;
xxxxxx是指root的密码
以上就是centos7.6安装MySql5.7+的步骤