1、下载并安装MySql
# mysql官方的yum repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# 安装yum repository
yum -y install mysql57-community-release-el7-10.noarch.rpm
# 安装Mysql服务器
yum -y install mysql-community-server
2、Mysql数据库设置
# 启动mysql
systemctl start mysqld.service
# 查看mysql运行状态
systemctl status mysqld.service
# Mysql服务启动后,获得root的密码
grep "password" /var/log/mysqld.log
# 登录mysql
mysql -uroot -p
# 输入上一步获得的初始密码,MYSQL默认必须修改密码才能正常使用
# 修改初始密码(密码过于简单会报错)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
# 卸载 Yum Repository,因为每次 yum 操作都会自动更新
yum -y remove mysql57-community-release-el7-10.noarch
# 此时远程登录数据库会报错,原因是没有授权
#任何主机
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
#指定主机
mysql> GRANT ALL PRIVILEGES ON *.* TO 'jack'@’47.97.1.123’ IDENTIFIED BY '123456' WITH GRANT OPTION;
# 设置后刷新权限
mysql>flush privileges;
3、重启mysql服务
service mysqld restart