Ubuntu20.04 mysql升级为8.0,涉及到caching_sha2_password的问题,正在解决
安装mysql-server及mysql-client
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
为了不侵占系统资源,我将mysql的data目录放在家目录下,并将该目录的访问权限为mysql这个用户名:
cd ~
mkdir mysql
sudo chown -R mysql:mysql /home/XXX/mysql
修改mysql配置
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
三个地方做了修改,一是为了暂时提供权限添加skip-grant-tables,二是修改datadir=/home/XXX/mysql,
为了后续可以承载更多的数据量,三是增加了输入文件最大大小至150M
# * Basic Settings
#
datadir=/home/XXX/mysql
skip-grant-tables
# * Fine Tuning
#
max_allowed_packet = 150M
ESC+:wq保存退出
启动mysql
sudo service mysql start
查看mysql是否启动使用
ps -A|grep mysql
因为Ubuntu有个AppArmor,是一个Linux系统安全应用程序,类似于Selinux,AppArmor默认安全策略定义个别应用程序可以访问系统资源和各自的特权,如果不设置服务的执行程序,即使你改了属主属组并0777权限,也是对服务起不到作用。
ok,apt安装下MySQL默认数据目录是/var/lib/mysql,其它的目录权限都不可。开始修改:
sudo vim /etc/apparmor.d/usr.sbin.mysqld
找到:
# Allow data dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
# Allow data files dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
修改为:
Allow data dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
/home/XXX/mysql/ r,
/home/XXX/mysql/** rwk,
Allow data files dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
/home/XXX/mysql/ r,
/home/XXX/mysql/** rwk,
重启apparmor服务:
service apparmor restart
再初始化mysql
cd /usr/bin/
sudo mysqld --initialize --user=mysql --datadir=/home/XXX/mysql
service mysql restart
进入mysql
mysql -uroot -p
Ubuntu18.04 使用mysql 5.7之前版本,修改密码需要password函数:
无需输入密码,直接回车跳过,设置密码为'123456'
mysql>use mysql;
mysql>select user,plugin from user;
mysql>update user set authentication_string=password('123456'),plugin='mysql_native_password' where user='root';
mysql>select user, plugin from user;
mysql>flush privileges;
mysql>exit;
Ubuntu20.04 mysql8.0版本,因为已经取消了password函数,所以更改密码时不一样
mysql>use mysql;
mysql>select user,plugin from user;
mysql>UPDATE user SET authentication_string='pwd123456',plugin='mysql_native_password' WHERE user='root';
mysql>select user, plugin from user;
mysql>flush privileges;
mysql>select user, plugin from user;
mysql>exit;
注释掉之前修改
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
* Basic Settings
skip-grant-tables
ESC+:wq保存退出
启动mysql:
sudo service mysql restart
mysql -uroot -p
启动mysql,至此mysql5.7之前可以正常使用了,如果有问题,可以参考[//www.greatytc.com/p/df975209de96](//www.greatytc.com/p/df975209de96)
重新设置密码
但mysql8.0 报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
正在解决mysql8.0带来的caching_sha2_password解决办法
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456';
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
root@ubuntu:# service mysql start
root@ubuntu:# mysql -uroot -p