1、下载YUM源文件
http://dev.mysql.com/downloads/repo/yum/
或者
sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
2.安装MySQL
sudo yum -y install mysql-community-server
3.安全设置
sudo /usr/bin/mysql_secure_installation
选择相应的Yes NO
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
4.启动MySQL
sudo /usr/bin/systemctl enable mysqld#开机启动
sudo /usr/bin/systemctl start mysqld #启动服务
5.防火墙设置
firewall-cmd --permanent --zone=trusted --add-source=192.0.2.10/32
firewall-cmd --permanent --zone=trusted --add-port=3306/tcp
firewall-cmd --reload
6.创建用户
mysql -u root -p mysql
mysql> create database newdb;
mysql> grant all on newdb.* to 'newuser'@'localhost' identified by 'password';
mysql> quit
登录用户
mysql -u newuser-p -h localhost newdb