由于MySQL在CentOS7中收费了,所以已经不支持MySQL了,取而代之在CentOS7内部集成了mariadb,而安装MySQL的话会和MariaDB的文件冲突,所以需要先卸载掉MariaDB.
⒈卸载MariaDB
rpm -qa | grep mariadb 查询是否安装了MariaDB rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 强制卸载 yum install vim libaio net-tools 安装MySQL依赖
⒉安装MySQL
①下载MySQL官网的repo源
https://dev.mysql.com/downloads/repo/yum/
②安装yum repo文件
rpm -ivh mysql80-community-release-el7-2.noarch.rpm
执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo mysql-community-source.repo
③更新yum缓存
yum clean all yum makecache
④安装MySQL
sudo yum install mysql-server
⒊启动MySQL
①启动MySQL服务
systemctl start mysqld.service
②查看MySQL服务状态
systemctl status mysqld.service
③将MySQL设为开机启动
systemctl enable mysqld systemctl daemon-reload
④修改root密码
⑴获取默认root密码
MySQL安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。
grep 'temporary password' /var/log/mysqld.log
得到如下内容:
2019-03-02T10:13:04.628699Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fIwo)pVrk0r/
fIwo)pVrk0r/ 为默认root密码
⑵使用默认的root密码登录并修改
mysql -u root -p
MySQL对密码强度要求较高,需要包含大小写字母、数字和特殊字符
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Test@123';
⑤设置MySQL服务器的安全配置
mysql_secure_installation
Set root password? [Y/n] y [设置root用户密码]
Remove anonymous users? [Y/n] y [删除匿名用户]
Disallow root login remotely? [Y/n] y [禁止root远程登录]
Remove test database and access to it? [Y/n] y [删除test数据库]
Reload privilege tables now? [Y/n] y [刷新权限]
⑥设置MySQL远程连接
use mysql; SELECT user, host, plugin from mysql.user; update user set host='%' where user='root'; flush privileges;
⑦开放3306端口
firewall-cmd --permanent --add-port=3306/tcp firewall-cmd --reload