1.在使用wget命令之前,先要安装wget:
[root@localhost ~]# yum install wget
如图安装完毕:
2.去mysql官网下载yum源rpm安装包:
MySQL :: Download MySQL Yum Repository
把红框中的文件名复制下来,追加在http://dev.mysql.com/get/后面,即:
http://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
执行命令:
[root@localhost ~]# wget http://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
3.安装mysql源:
[root@localhost ~]# yum localinstall mysql80-community-release-el7-2.noarch.rpm
如图安装完毕:
4.验证mysql源是否安装成功:
[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"
看到下面这些信息说明安装成功:
5.通过yum来安装mysql:
[root@localhost ~]# yum install mysql-community-server
如图安装完毕:
6.启动mysql服务:
[root@localhost ~]# systemctl start mysqld
然后我们查看一下mysql的状态:
[root@localhost ~]# systemctl status mysqld
如图说明启动成功:
附:停止mysql的命令:systemctl stop mysqld
7.设置开机启动:
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
8.设置密码:
MySQL在安装完成之后会在 /var/log/mysqld.log文件中生成一个默认密码,我们需要找到root的默认密码,然后登陆mysql进行修改。
找到原来的密码:
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
红框内就是原密码:
设置新密码:这里一定要记得在命令末尾加上分号。
[root@localhost ~]# set password for 'root'@'localhost'=新密码;
9.重启数据库,使配置生效:
[root@localhost ~]# systemctl restart mysqld