- 添加MySQL官方的Yum仓库
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
- 安装MySQL服务器
sudo yum install mysql-community-server
在安装过程中遇到了如下错误:
使用如下命令去解决:
yum --enablerepo=mysql80-community install -y mysql-community-server --nogpgcheck
- 安装完成启动MySQL服务
sudo systemctl start mysqld
- 查看MySQL服务的状态
sudo systemctl status mysqld
- 设置MySQL服务开机自启
sudo systemctl enable mysqld
- 安全配置MySQL(设置root密码,移除匿名用户,禁止root远程登录等)
sudo mysql_secure_installation
此时要求输入root密码,可以使用如下命令获取初始密码
sudo grep 'temporary password' /var/log/mysqld.log
初始密码如下图:
下面会要求你重置新密码,一大段省略。
- 登录MySQL
mysql -u root -p
输入新密码
- 创建新用户并授权(替换test和Huoo@&&@5099为你想设置的用户名和密码)
CREATE USER 'test'@'%' IDENTIFIED BY 'Huoo@&&@5099';
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
如果只需要本地连接可以这样写:
CREATE USER 'test'@'localhost' IDENTIFIED BY 'Huoo@&&@5099';
GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
- 退出MySQL
exit;
- 防火墙设置