yum安装指定版本的mysql https://www.51anidea.com/forum.php?mod=viewthread&tid=513 (出处: Linux教程网) 一、环境 CentOS 7.4 二、安装方法 1、下载mysql源 #wget http://repo.mysql.com/mysql80-community-release-el7.rpm (如果要安装其他版本的mysql,可以去 http://repo.mysql.com/ 下面查找其他版本的mysql) 2、安装mysql源 #rpm -ivh mysql80-community-release-el7.rpm 3、安装mysql #yum -y install mysql-server 4、更改权限 #chown mysql:mysql -R /var/lib/mysql 5、初始化 #mysqld --initialize 6、启动mysql #systemctl start mysqld

(1)如果无法启动(也许是与之前的mysql版本不兼容) 查看日志 #cat /var/log/mysqld.log 2019-09-14T06:28:57.838520Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

2019-09-14t06:28:57.838520Z 0[错误][my-010457][服务器]--已指定初始化,但date目录中有文件。中止。

原来是date目录中有文件。

(2)解决办法 找到配置文件,修改date目录 vi /etc/my.cnf

将原目录datedir=/var/lib/mysql修改为datedir=/var/lib/mysql1 再新建目录 #mkdir datedir=/var/lib/mysql1

或者直接删除/var/lib/mysql的文件 #rm -r /var/lib/mysql

7、查看mysql的日志,找到mysql的初始密码 #cat /var/log/mysqld.log 找到以下信息: 2019-03-05T00:26:37.417710Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: :18dKSAditnu

故mysql的初始密码是 18dKSAditnu

8、更改mysql的密码(不更改的话,无法使用mysql) #mysqladmin -u root -p"18dKSAditnu" password "新密码" 执行后会出现以下提示信息: mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

以上只是警告信息,没有影响

9、登录mysql #mysql -u root -p

[root@localhost ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.15 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)

至此,mysql8.0安装完毕。