1.检测自身系统是否安装MYSQL
yum list installed | grep mysql
2.删除系统自带MYSQL及其依赖
yum -y remove mysql-libs.x86_64
3.给CentOS添加rpm源,并且选择较新的源
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum localinstall mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql
yum-config-manager --disable mysql55-community
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
yum repolist enabled | grep mysql
如果第一步报错,则使用如下代码替换
wget --no-check-certificate dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
4.安装MYSQL服务器
yum install mysql-community-server
- 启动MYSQL
service mysqld start
- 查看MYSQL是否自启动,并且设置开启自启动
chkconfig --list | grep mysqld
chkconfig mysqld on
7.查询MYSQL的初始密码
grep 'temporary password' /var/log/mysqld.log
8.登录数据库
mysql -u root -p
9.修改密码
SET PASSWORD = PASSWORD('123456')
重新登陆
10.设置MYSQL允许远程访问
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql>FLUSH PRIVILEGES;
mysql>exit;
打开防火墙配置文件
vi /etc/sysconfig/iptables
增加下面一行
-A INPUT -m state--state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启防火墙
service iptables restart
代码参考文章:https://www.jianshu.com/p/1bc47742c11c