下载和添加仓库
1.wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2.sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
3.yum update
安装Mysql
1.yum install mysql-server
2.systemctl start mysqld
配置Mysql
运行脚本文件
1.mysql_secure_installation (提示输入root密码,初始为null)
连接Mysql
1.mysql -uroot -p
查看MySql的编码并修改
#查看mysql的编码
mysql>show variables like '%character%’;
可以看到database和server编码都为latin1,我们修改为utf8
#1.将my-default.cnf 拷贝到 /etc/my.cnf
cp /usr/share/doc/mysql/my-default.cnf /etc/my.cnf
#2.编辑/usr/my.cnf在[client](如果没有就自己加)下增加
default-character-set = utf8
#3.编辑/usr/my.cnf在[mysqld]下增加
character_set_server = utf8
#4.重启MySql服务
systemctl restart mysql.service
#5.重现连接mysql并查看编码如下:
mysql -uroot –proot
mysql>show variables like '%character%’;
允许远程登录
授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
1.mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
2.mysql>FLUSH PRIVILEGES;
开放3306端口
1.firewall-cmd --zone=public --add-port=3306/tcp --permanent
2.firewall-cmd --reload