一 检查本地是否安装过其他版本的mysql
[root@Linux1 ~]# rpm -qa|grep -i mysql
MySQLxxxxxxx
二 若有安装则需要先卸载
[root@Linux1 ~]# rpm -e --nodeps MySQLxxxxxxx
三 由于有些版本自带的有mariadb(本质是mysql,只是名字不一样而已),需要先检查是否有mariadb,若有则卸载
[root@Linux1 ~]# rpm -qa|grep -i mariadb
mariadbxxxxxxx
四 卸载mariadb
[root@Linux1 ~]# rpm -e --nodeps mariadbxxxxxxx
五 下载mysql 5.5的服务器和客户端的安装包
[root@Linux1 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-server-5.5.59-1.el7.x86_64.rpm
[root@Linux1 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-client-5.5.59-1.el7.x86_64.rpm
六 安装服务器和客户端
[root@Linux1 ~]# rpm -ivh MySQL-server-5.5.59-1.el7.x86_64.rpm--force —nodeps
[root@Linux1 ~]# rpm -ivh MySQL-client-5.5.59-1.el7.x86_64.rpm--force —nodeps
//如果以上两条命令报错,则修改为
[root@Linux1 ~]# rpm -ivh MySQL-server-5.5.59-1.el7.x86_64.rpm
[root@Linux1 ~]# rpm -ivh MySQL-client-5.5.59-1.el7.x86_64.rpm
七 启动mysql 设置密码
启动mysql (第一次启动mysql是不需要密码的)
[root@Linux1 ~]# service mysql start
[root@Linux1 ~]# mysql
mysql>
mysql> exit
Bye
退出mysql 修改密码(此时只是退出mysql,不能关掉mysql服务,否则将修改失败)
以下两个修改密码方式选其一即可(推荐使用第一种交互式修改root密码,选择交互式修改后,则无需手动进行八、九操作)
[root@Linux1 ~]# /usr/bin/mysql_secure_installation
[root@Linux1 ~]# /usr/bin/mysqladmin -u root password “输入密码”
八 将mysql添加到开机启动项
至此全部完成,附带libaio依赖的下载及mysql的停止命令和随机启动
[root@Linux1 ~]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
//mysql的停止命令
service mysql stop
//mysql的随机启动命令
chkconfig mysql on
//检查mysql 随机启动是否设置成功(桌面版linux启动级别为5,mini版linux默认为3)
[root@Linux1 ~]# chkconfig --list|grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
九 添加root允许远程连接
mysql> grant all privileges on *.* to root@'%' identified by 'root’;
mysql> flush privileges;
安装成功(进行登录):
[root@Linux1 ~]# mysql -u root -p
Enter password: