一、完整卸载已安装的MySQL服务
1.停止已安装的MySQL服务
# service mysqld stop
2.查看已安装的MySQL服务
# rpm -qa | grep mysql
mysql-community-common-5.7.22-1.el6.x86_64
mysql57-community-release-el6-11.noarch
mysql-community-client-5.7.22-1.el6.x86_64
mysql-community-server-5.7.22-1.el6.x86_64
mysql-community-devel-5.7.22-1.el6.x86_64
mysql-community-libs-5.7.22-1.el6.x86_64
3.逐个卸载已安装的MySQL服务
# rpm -e --nodeps mysql-community-common-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql57-community-release-el6-11.noarch
# rpm -e --nodeps mysql-community-client-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql-community-server-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql-community-devel-5.7.22-1.el6.x86_64
# rpm -e --nodeps mysql-community-libs-5.7.22-1.el6.x86_64
4.查找并删除已安装的MySQL服务的安装目录及文件
4.1.查找
# find / -name mysql
/usr/share/mysql
/var/lib/mysql
/var/lib/mysql/mysql
4.2.逐个删除
# rm -rf /usr/share/mysql/
# rm -rf /var/lib/mysql/
二、sftp上传文件:mysql57-community-release-el6-11.noarch.rpm,具体上传过程可以参照博客(CI系列之一:JDK安装及配置)
三、安装MySQL
1.移动mysql57-community-release-el6-11.noarch.rpm至安装目录
# mv mysql57-community-release-el6-11.noarch.rpm /usr/local
2.切换到安装目录
# cd /usr/local
3.安装rpm
# yum -y install mysql57-community-release-el6-11.noarch.rpm
4.安装MySQL
# yum -y install mysql-server mysql mysql-devel
四、设置MySQL用户root的登录密码
1.正常模式启动MySQL,进行数据库的初始化
# service mysqld start
2.停止mysql服务,已安全模式启动MySQL
# service mysqld stop
# mysqld_safe --skip-grant-tables&
3.安全模式下免密码登录进行root登录密码设置
3.1.安全模式下免密码登录
#输入命令之后,连续点击enter键,无需输入登录密码
# mysql -uroot -p
3.2.设置登录密码
> update mysql.user set authentication_string=password('******') where User = 'root' and Host='localhost';
3.3.刷新权限使密码生效
> flush privileges
3.4.退出MySQL客户端
> quit
4.重启MySQL服务,正常模式启动后重设密码password,使能够正常操作MySQL
4.1.重启MySQL服务
# service mysqld restart
4.2.用刚刚设置的密码登录
# mysql -uroot -p
4.3.重设password
> set password for 'root'@'localhost' = password('******');
4.4.刷新权限使密码生效
> flush privileges
4.5.退出MySQL客户端
> quit
五、设置MySQL开机自启
1.设置MySQL开机自启
# chkconfig mysqld on
2.查看是否设置成功,成功信息如下
# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
六、设置MySQL远程登录
1.编辑防火墙配置文件,新增以下一行内容,开放3306端口
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
2.重启防火墙,使开放的端口生效
# service iptables restart
3.查看端口是否成功开放
# service iptables status
4.使用密码登录MySQL,设置MySQL远程登录
# mysql -uroot -p
> update mysql.user set Host = '%' where User = 'root';
5.刷新权限使远程登录生效
> flush privileges
6.退出MySQL客户端
> quit