Ubuntu安装MySQL
安装mysql
MySQL
sudo apt install docker.io mysql-client -y
sudo docker pull mysql:5.7
sudo docker run --restart=always -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
报错 ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘解决方法
1、问题描述
在使用如下指令进入mysql shell界面时:
mysql -u root -p
2、问题原理
一般出现这种情况多数是安装新版本mysql,root密码是随机的,也不是空密码,所以要通过查看随机密码进入,再进行修改原来的密码。
3、解决方法
3.1 其它用户登录MySQL
既然我们无法通过root用户进入MySQL,那我们就只能通过其他用户登录MySQL。
在我们下载安装MySQL的过程中,系统会自动给我们创建一个用户,我们借助如下指令便可以查看该用户信息:
sudo cat /etc/mysql/debian.cnf
然后使用该用户名和密码进入MySQL:
ubuntu@ubuntu:~/DjangoWorkspace$ mysql -udebian-sys-maint -p
Enter password:
mysql>
3.2 查看user表
在mysql中输入指令,结果如下:
use mysql;
select user,plugin from user;
3.3 修改root密码格式
# 修改其密码格式
update user set plugin='mysql_native_password' where user='root';
# 查询其用户
select user,plugin from user;
# 刷新权限
flush privileges;
3.4 增加root密码
# 修改root账号密码
alter user 'root'@'localhost' identified by 'root';
# 在次刷新权限
flush privileges;
# 退出登录
exit
3.5 重启mysql服务
service mysql restart
输入登录密码重启服务
3.6 root登录
mysql -u root -p
安装来自上家公司运维笔记
报错解决原文链接:https://blog.csdn.net/m0_70885101/article/details/127414184