🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 安装MySQL 打开MySQL官网的下载页`https://www.mysql.com/downloads/`,点击图示中的Yum Repository菜单 :-: ![](https://box.kancloud.cn/023fca208fe2700f66a68fa5f8cba76b_1116x435.jpg) 往下拉,找到适合MySQL80的下载链接,点进去,不用注册登录,在页面最下端找到“No thanks, just start my download.”,右键复制下载链接。 ![](https://box.kancloud.cn/42c011fe37e793d579534b6f5a243929_1172x129.jpg) ~~~ https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm ~~~ 该页面也提供了MySQL Yum源的使用手册,点击链接进去就可以查看了: :-: ![](https://box.kancloud.cn/71616ba266c235d6e40e0ab50a68026f_616x158.jpg) 导入Yum源: ~~~ [root@localhost ~]# rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm [root@localhost ~]# yum makecache fast ~~~ Yum源导入成功,可以安装MySQL8.0了 ~~~ [root@localhost ~]# yum install mysql-community-server ~~~ 显示: ~~~ =========================================================================================================== Package Arch Version Repository Size =========================================================================================================== Installing: mysql-community-server x86_64 8.0.12-1.el7 mysql80-community 349 M Transaction Summary =========================================================================================================== Install 1 Package Total download size: 349 M Installed size: 1.5 G Is this ok [y/d/N]: ~~~ > 注:为什么默认会安装最新版本,而且没有提供其它版本的MySQL供你选择?因为在`/etc/yum.repos.d/mysql-community.repo`中已经设置其它版本`disabled`了。如果你要安装其它版本的MySQL,只需要设置这个版本的`enabled=1`即可。 确认是MySQL8.0.12无误,输入`y`确认执行安装。 349M,需要一点时间安装。安装完成后,检查版本: ~~~ [root@localhost ~]# mysql -V ~~~ 输出: ~~~ mysql Ver 8.0.12 for Linux on x86_64 (MySQL Community Server - GPL) ~~~ 版本正确。现在配置MySQL服务: 检查mysqld服务是否启动: ~~~ [root@localhost ~]# systemctl status mysqld.service ~~~ 返回: ~~~ ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html ~~~ 没有启动,我们启动它: ~~~ [root@localhost ~]# systemctl enable mysqld.service [root@localhost ~]# systemctl start mysqld.service [root@localhost ~]# systemctl status mysqld.service ~~~ 结果: ~~~ ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2018-08-15 12:31:09 CST; 10s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 1703 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 1773 (mysqld) Status: "SERVER_OPERATING" CGroup: /system.slice/mysqld.service └─1773 /usr/sbin/mysqld Aug 15 12:31:00 localhost.localdomain systemd[1]: Starting MySQL Server... Aug 15 12:31:09 localhost.localdomain systemd[1]: Started MySQL Server. ~~~ 小绿灯闪耀,天气真好。 安装程序为`root@localhost`创建了初始密码,通过下面的命令查看: ~~~ [root@localhost log]# grep 'temporary password' /var/log/mysqld.log ~~~ 输出: ~~~ 2018-08-15T06:11:28.416464Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 8Ftm8eb!S9/( ~~~ 这里就是你的初始密码了,需要先修改它: ~~~ [root@localhost log]# mysql -uroot -p ~~~ 输入初始密码: ~~~ mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; ~~~ ~~~ Query OK, 0 rows affected (0.01 sec) ~~~ ~~~ mysql> show databases; ~~~ ~~~ +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.02 sec) ~~~ ~~~ mysql> quit'; ~~~ 关闭虚拟机,拍个快照吧 由于MySQL 8.0 开始改变了身份验证插件,使用以前版本的客户端连接时,可能会报Authentication plugin 'caching\_sha2\_password' cannot be loaded错误,如果出现这种情况,参考下面文章的方案解决: [http://www.cnblogs.com/hlhx/p/mysqlsha2.html](http://www.cnblogs.com/hlhx/p/mysqlsha2.html) [https://blog.csdn.net/faye0412/article/details/80396113](https://blog.csdn.net/faye0412/article/details/80396113)