Linux安装mysql5.6.33
1、下载mysql安装包:
下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
下载版本:我这里选择的5.6.33,通用版,linux下64位
也可以直接复制64位的下载地址,通过命令
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz --no-check-certificate tar -xvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
2、卸载老版本MySQL
查找并删除mysql有关的文件
find / -name mysql
rm -rf 上边查找到的路径,多个路径用空格隔开
#或者下边一条命令即可
find / -name mysql|xargs rm -rf
![](https://upload-images.jianshu.io/upload_images/1899977-305617e34955e4d3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3、在安装包存放目录下执行命令解压文件:
tar -xvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz
![](https://upload-images.jianshu.io/upload_images/1899977-f8b6174388c8531d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4、重命名解压后的文件
mv mysql-5.6.31-linux-glibc2.5-x86_64/ mysql
![](https://upload-images.jianshu.io/upload_images/1899977-7c5b2ca42cf623e1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5、添加mysql用户组和mysql用户
先检查是否有mysql用户组和mysql用户
groups mysql
![](https://upload-images.jianshu.io/upload_images/1899977-cc398fb960e0cb76.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
若无,则添加;
groupadd mysql
useradd -r -g mysql mysql
![](https://upload-images.jianshu.io/upload_images/1899977-f80edc428a9e61cf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
若有,则跳过;
![](https://upload-images.jianshu.io/upload_images/1899977-6aee55a3221c0446.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
6、进入mysql目录更改权限
cd mysql/
chown -R mysql:mysql ./
![](https://upload-images.jianshu.io/upload_images/1899977-ad018015ea413b53.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
7、执行安装脚本
./scripts/mysql_install_db --user=mysql
![](https://upload-images.jianshu.io/upload_images/1899977-e07b0b2383d9fc81.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
安装完之后修改当前目录拥有者为root用户,修改data目录拥有者为mysql
chown -R root:root ./
chown -R mysql:mysql data
![](https://upload-images.jianshu.io/upload_images/1899977-4e2b1c5c2fd75d24.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Paste_Image.png
8、更改mysql密码
上一步安装脚本执行输出的日志中告诉我们如何更改密码了
![](https://upload-images.jianshu.io/upload_images/1899977-ccd379696682e6c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
但是如果直接执行这两条命令就会报错
![](https://upload-images.jianshu.io/upload_images/1899977-151811b1ccfd6b75.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
因为这时还没有启动mysql,这算是一个坑。启动方法如下:
./support-files/mysql.server start
![](https://upload-images.jianshu.io/upload_images/1899977-31eacd5fca58b5b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
如果MySQL启动报错,则可能是已经存在MySQL进程,杀掉即可
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-6572db71fdf5faa7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
杀掉后再启动即可。
或者是有其他的mysql文件干扰了mysql的启动,所以在安装之前要删除其他的mysql目录,如果一直启动不了,那就删除掉所有的mysql目录,重新安装
![](https://upload-images.jianshu.io/upload_images/1899977-f417bdc69058de74.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
MySQL启动之后再执行如下命令更改密码:
./bin/mysqladmin -u root -h localhost.localdomain password '123456'
![](https://upload-images.jianshu.io/upload_images/1899977-d1a1c4478febf199.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
密码更改后即可登录MySQL
./bin/mysql -h127.0.0.1 -uroot -p123456
![](https://upload-images.jianshu.io/upload_images/1899977-c22b674ff3f96009.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
9、修改配置
但是如果./bin/mysql -uroot -p123456登陆,系统会报错:Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";
具体可以参考帖子:https://blog.csdn.net/hjf161105/article/details/78850658
验证办法:
./bin/mysql -uroot -p -S /var/lib/mysql/mysqld.sock
如果执行上述命令可以连接mysql,则使用下面解决办法
解决办法:
ln -s /var/lib/mysql/mysqld.sock /tmp/mysql.sock
ls /tmp/
同时,将etc/my.cnf文件的bind-address = 127.0.0.1 更改为 bind-address = 0.0.0.0,如果配置文件中没有这个配置,则手动添加上
这一步可有可无:
登录之后将其他用户的密码也可改为root
update mysql.user set password=password('root') where user='root';
flush privileges;
![](https://upload-images.jianshu.io/upload_images/1899977-010a473ab72f59fc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
10、关闭防火墙
service iptables stop
11、增加远程登录权限
上一步即可本地登录,但远程登录会报错
![](https://upload-images.jianshu.io/upload_images/1899977-2185d688960a5413.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
为解决这一问题,需要本地登陆MySQL后执行如下命令
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;
![](https://upload-images.jianshu.io/upload_images/1899977-8488efcf4d8d96a1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
执行之后即可远程登录
转发自链接: https://blog.csdn.net/wwd0501/article/details/71171614