环境说明:centos7.3
如果原先安装过mysql,请先卸载
卸载mysql
1.停止mysql服务
service mysql stop
2.将whereis mysql查出来的目录或文件全部删除
3.find / -name mysql
将查出来的与mysql相关的删除
下载mysql5.6
1.进入mysql官网 https://dev.mysql.com/downloads/
点击MYSQL Community Server
点击MySQL Community Server5.6
点击Download
不登录,点击no thanks ,just start my download 即可下载
安装mysql
1.卸载mariadb
由于有些版本自带的有mariadb(本质是mysql,只是名字不一样而已),需要先检查是否有mariadb,若有则卸载
[root@iZuf6ih01h8fzeziddwkfdZ opt]#rpm -qa|grep -i mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
2.安装依赖包
2.1安装依赖perl
yum install -y perl-Module-Install.noarch
2.2安装依赖libaio
yum -y install libaio.so.1
3.将rpm安装文件拷贝至/usr/local/mysql5.6src目录下
安装MySQL-server-5.6.42-1.el7.x86_64.rpm,MySQL-client-5.6.42-1.el7.x86_64.rpm,MySQL-devel-5.6.42-1.el7.x86_64.rpm
[root@localhost mysql5.6src]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm
[root@localhost mysql5.6src]# rpm -ivh MySQL-client-5.6.42-1.el7.x86_64.rpm
[root@localhost mysql5.6src]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm
4.修改配置文件位置
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
1.执行命令service mysql start启动mysql
其他命令:
service mysql stop:停止mysql
service mysql restart:重启mysql
2.获取初始密码,查看root账号密码
vi /root/.mysql_secret
使用初始密码2Uhty6qE_ITpdyAY进行登录
登录后修改密码
mysql> SET PASSWORD = PASSWORD('123456'); #设置密码为123456
mysql>q;
3.使用修改后的密码登录,授予root用户远程登录权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
参考地址