1. Clean up the environment
① Uninstall the installed mysql
$ rpm -qa | grep mysql
# 结果如下
mysql-community-common-8.0.18-1.el7.x86_64
mysql-community-client-8.0.18-1.el7.x86_64
mysql-community-libs-8.0.18-1.el7.x86_64
# 使用以下命令依次删除上面的程序
$ yum remove mysql-xxx-xxx-
② Delete the mysql configuration file
$ find / -name mysql|xargs rm -fr
③ Delete MariaDB files
$ rpm -qa | grep mariadb
$ rpm -e mariadb-xxx --nodeps
2. Download the mysql8.0 package
3. Install mysql8.0
① Create a directory
$ mkdir -p /usr/local/mysql && cd /usr/local/mysql
$ rz mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar.tar
$ tar xf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar.tar
[root@sonar /usr/local/mysql]# ll
total 1.3G
mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar.tar
mysql-community-client-8.0.18-1.el7.x86_64.rpm
mysql-community-common-8.0.18-1.el7.x86_64.rpm
mysql-community-devel-8.0.18-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm
mysql-community-libs-8.0.18-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm
mysql-community-server-8.0.18-1.el7.x86_64.rpm
mysql-community-test-8.0.18-1.el7.x86_64.rpm
②Install
$ rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm --nodeps --force
$ rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm --nodeps --force
$ rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm --nodeps --force
$ rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm --nodeps --force
$ yum install libaio -y
# 检查
[root@sonar /usr/local/mysql]# rpm -qa | grep mysql
mysql-community-common-8.0.18-1.el7.x86_64
mysql-community-libs-8.0.18-1.el7.x86_64
mysql-community-server-8.0.18-1.el7.x86_64
mysql-community-client-8.0.18-1.el7.x86_64
③ Initialization
$ mysqld --initialize
$ chown mysql:mysql /var/lib/mysql -R
$ systemctl start mysqld.service
$ systemctl enable mysqld
④Start error
[root@sonar /usr/local/mysql]# systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
# 查看日志
[root@sonar /var/lib]# cat /var/log/mysqld.log|grep 'initialize'
2020-04-16T16:10:57.488085Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
# 查看配置文件
[root@sonar /var/lib]# cat /etc/my.cnf|grep "datadir"
datadir=/var/lib/mysql
# 解决
将这个mysql目录备份后重启即可,由于这个mysql目录含有证书认证,改名备份后启动不再进行认证。
$ cd /var/lib/ && mv mysql mysql.bak
$ systemctl start mysqld
$ systemctl enable mysqld
$ systemctl status mysqld
$ netstat -anlptu|grep 3306 # 监听33060和3306证明启动正常
⑤ Change password
- View password
[root@sonar ~]# cat /var/log/mysqld.log | grep password
2020-04-16T16:13:23.042762Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: MbIq4xlV6-3*
- log in
# 使用刚才的密码登录,复制粘贴即可
$ mysql -uroot -p
- change Password
# 密码规则:至少大写+小写+符号+数字
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Oldboy@123';
- Authorize remote access users
create user 'root'@'%' identified with mysql_native_password by 'Oldboy@123';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
Reprinted: https://www.pingface.com/archives/mysql80