1,cd /usr/local/software 这个目录下面
2,wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm 下载mysql8.0的rpm
![](https://i-blog.csdnimg.cn/blog_migrate/8da5655b9e27f66fed9c40980747a23c.png)
3,先安装 yum install -y mysql80-community-release-el7-1.noarch.rpm,接着在使用yum -y install mysql-community-server 安装mysql ,下面是安装日志,此过程可能比较耗时,需要下载的东西比较多,建议在网络好的时候操作
[root@localhost software]# yum -y install mysql-community-server 已加载插件:fastestmirror base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql80-community | 2.5 kB 00:00:00 nginx | 2.9 kB 00:00:00 updates | 3.4 kB 00:00:00 Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.huaweicloud.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 mysql-community-server.x86_64.0.8.0.13-1.el7 将被 安装 --> 正在处理依赖关系 mysql-community-common(x86-64) = 8.0.13-1.el7,它被软件包 mysql-community-server-8.0.13-1.el7.x86_64 需要 --> 正在处理依赖关系 mysql-community-client(x86-64) >= 8.0.0,它被软件包 mysql-community-server-8.0.13-1.el7.x86_64 需要 --> 正在处理依赖关系 net-tools,它被软件包 mysql-community-server-8.0.13-1.el7.x86_64 需要 --> 正在检查事务 ---> 软件包 mysql-community-client.x86_64.0.8.0.13-1.el7 将被 安装 --> 正在处理依赖关系 mysql-community-libs(x86-64) >= 8.0.0,它被软件包 mysql-community-client-8.0.13-1.el7.x86_64 需要 ---> 软件包 mysql-community-common.x86_64.0.8.0.13-1.el7 将被 安装 ---> 软件包 net-tools.x86_64.0.2.0-0.22.20131004git.el7 将被 安装 --> 正在检查事务 ---> 软件包 mariadb-libs.x86_64.1.5.5.44-2.el7.centos 将被 取代 --> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要 --> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-6.el7.x86_64 需要 ---> 软件包 mysql-community-libs.x86_64.0.8.0.13-1.el7 将被 舍弃 --> 正在检查事务 ---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.13-1.el7 将被 舍弃 --> 解决依赖关系完成 依赖关系解决 ======================================================================================================================================================================================================================= Package 架构 版本 源 大小 ======================================================================================================================================================================================================================= 正在安装: mysql-community-libs x86_64 8.0.13-1.el7 mysql80-community 2.3 M 替换 mariadb-libs.x86_64 1:5.5.44-2.el7.centos mysql-community-libs-compat x86_64 8.0.13-1.el7 mysql80-community 2.1 M 替换 mariadb-libs.x86_64 1:5.5.44-2.el7.centos mysql-community-server x86_64 8.0.13-1.el7 mysql80-community 381 M 为依赖而安装: mysql-community-client x86_64 8.0.13-1.el7 mysql80-community 26 M mysql-community-common x86_64 8.0.13-1.el7 mysql80-community 554 k net-tools x86_64 2.0-0.22.20131004git.el7 base 305 k 事务概要 ======================================================================================================================================================================================================================= 安装 3 软件包 (+3 依赖软件包) 总计:412 M 总下载量:381 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. 警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-server-8.0.13-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY===========================-] 6.7 MB/s | 380 MB 00:00:00 ETA mysql-community-server-8.0.13-1.el7.x86_64.rpm 的公钥尚未安装 mysql-community-server-8.0.13-1.el7.x86_64.rpm | 381 MB 00:00:33 从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥 导入 GPG key 0x5072E1F5: 用户ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>" 指纹 : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 软件包 : mysql80-community-release-el7-1.noarch (@/mysql80-community-release-el7-1.noarch) 来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : mysql-community-common-8.0.13-1.el7.x86_64 1/7 正在安装 : mysql-community-libs-8.0.13-1.el7.x86_64 2/7 正在安装 : mysql-community-client-8.0.13-1.el7.x86_64 3/7 正在安装 : net-tools-2.0-0.22.20131004git.el7.x86_64 4/7 正在安装 : mysql-community-server-8.0.13-1.el7.x86_64 5/7 正在安装 : mysql-community-libs-compat-8.0.13-1.el7.x86_64 6/7 正在删除 : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 7/7 验证中 : net-tools-2.0-0.22.20131004git.el7.x86_64 1/7 验证中 : mysql-community-libs-compat-8.0.13-1.el7.x86_64 2/7 验证中 : mysql-community-libs-8.0.13-1.el7.x86_64 3/7 验证中 : mysql-community-common-8.0.13-1.el7.x86_64 4/7 验证中 : mysql-community-server-8.0.13-1.el7.x86_64 5/7 验证中 : mysql-community-client-8.0.13-1.el7.x86_64 6/7 验证中 : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 7/7 已安装: mysql-community-libs.x86_64 0:8.0.13-1.el7 mysql-community-libs-compat.x86_64 0:8.0.13-1.el7 mysql-community-server.x86_64 0:8.0.13-1.el7 作为依赖被安装: mysql-community-client.x86_64 0:8.0.13-1.el7 mysql-community-common.x86_64 0:8.0.13-1.el7 net-tools.x86_64 0:2.0-0.22.20131004git.el7 替代: mariadb-libs.x86_64 1:5.5.44-2.el7.centos 完毕! |
4,启动mysql 使用: systemctl start mysqld.service
查看mysql启动状态: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 software]# systemctl start mysqld.service [root@localhost software]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 四 2018-11-01 07:06:00 CST; 2s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 2415 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 2483 (mysqld) Status: "SERVER_OPERATING" CGroup: /system.slice/mysqld.service └─2483 /usr/sbin/mysqld 11月 01 07:05:50 localhost.localdomain systemd[1]: Starting MySQL Server... 11月 01 07:06:00 localhost.localdomain systemd[1]: Started MySQL Server. |
5,查找初始密码 grep "password" /var/log/mysqld.log
![](https://i-blog.csdnimg.cn/blog_migrate/1d9403942109d03333c83e5201729f93.png)
6,使用初始密码登录 mysql -uroot -p
![](https://i-blog.csdnimg.cn/blog_migrate/1e5eff63a0409c24e97ed526423f7395.png)
7,修改root用户密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password';//密码规则要按照要求
8,修改语句 将root用户的localhost修改成为%
use mysql;
update user set host = '%' where user = 'root';
9,重新授权 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
10,刷新权限 flush privileges;
![](https://i-blog.csdnimg.cn/blog_migrate/eb0961dce3005de7f3ca04306058cf54.png)
11,为了可以让虚拟机外面的界面工具可以访问 先停止mysql 执行命令:systemctl stop mysqld.service
编辑:vi /etc/my.cnf
放开前面的#号 default-authentication-plugin=mysql_native_password
![](https://i-blog.csdnimg.cn/blog_migrate/5fa5f9e2bd493ef4348b4ba131036048.png)
13,先启动mysql
systemctl start mysqld.service
mysql -uroot -p
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'your-password123456';
FLUSH PRIVILEGES;
![](https://i-blog.csdnimg.cn/blog_migrate/5256f72b05ffba190f7489edc1acf663.png)
13,连接
![](https://i-blog.csdnimg.cn/blog_migrate/1a9b17bb306c21d4dabd39dfbc544d93.png)