传送门:https://www.cnblogs.com/wangdaijun/p/6132632.html
环境:
1、操作系统:CentOS release 6.8 (Final)
2、安装版本: mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
3、下载地址: http://dev.mysql.com/downloads/mysql/
4、下载说明:上边的下载地址是最新版的,如果想下载老版本可以点击页面中的超链接“ Looking for previous GA versions?”
5、特殊说明:Linux下MySQL5.6与MySQL5.7安装方法略有不同,本文以5.6为主
安装步骤
0、卸载老版本MySQL
查找并删除mysql有关的文件
Paste_Image.png
1、在安装包存放目录下执行命令解压文件:
Paste_Image.png
2、删除安装包,重命名解压后的文件
Paste_Image.png
3、添加mysql用户组和mysql用户
先检查是否有mysql用户组和mysql用户
Paste_Image.png
若无,则添加;
Paste_Image.png
若有,则跳过;
cd mysql/ chown -R mysql:mysql ./
./scripts/mysql_install_db --user=mysql
chown -R root:root ./ chown -R mysql:mysql data
![](https://upload-images.jianshu.io/upload_images/1899977-ccd379696682e6c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Paste_Image.png
但是如果直接执行这两条命令就会报错
./support-files/mysql.server start
ps aux|grep mysql kill -9 上边的进程号 #或者下边一条命令即可杀掉所有MySQL进程 ps aux|grep mysql|awk '{print $2}'|xargs kill -9
![](https://upload-images.jianshu.io/upload_images/1899977-f417bdc69058de74.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Paste_Image.png
MySQL启动之后再执行如下命令更改密码:
Paste_Image.png
密码更改后即可登录MySQL
Paste_Image.png
登录之后将其他用户的密码也可改为root
Paste_Image.png
7、增加远程登录权限
上一步即可本地登录,但远程登录会报错
grant all privileges on *.* to root@'%' identified by 'root'; flush privileges;
![](https://upload-images.jianshu.io/upload_images/1899977-45f2148fec4a53af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Paste_Image.png
8、将MySQL加入Service系统服务
Paste_Image.png
vim my.cnf #添加以下两条语句并保存退出 default-character-set=utf8 lower_case_table_names=1 max_allowed_packet=100M
![](https://upload-images.jianshu.io/upload_images/1899977-c7178785535c5175.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)