参考大佬博客,做个笔记。
原文链接:https://blog.youkuaiyun.com/qq_43288928/article/details/115269475
1. 查找账号密码的方法
-
直接通过
sudo apt-get install mysql-server
安装MySQL数据库(默认安装MySQL 8+) -
安装完成后,通过
cat /etc/mysql/debian.cnf
指令查看账号密码
-
通过user和password对应的值登录MySQL之后,便可修改root用户的密码
2. 设置密码
-
用
use mysql
指令,进入到 mysql 这个数据库中 -
用
select user,plugin,authentication_string from user;
指令查询当前用户 -
用
update user set plugin="caching_sha2_password" , authentication_string=sha2("1234",32) where user = "root";
指令将 user用户的密码设置为空 。 -
用
flush privileges;
指令刷新后,退出MySQL,使用mysql -uroot
即可登录。 -
使用 root 用户登录后,用
alter user 'root'@'localhost' identified with caching_sha2_password by '新密码';
即可为root用户设置新密码
3. 关于MySQL的几种身份验证插件
- mysql_native_password
- sha256_password
- caching_sha2_password
后续更新…
4. Navicat连接MySQL报1521错误
只需要将 root 用户的登录验证插件(caching_sha2_password)替换成 (mysql_native_password)即可。
5. 彻底删除MySQL
查看MySQL依赖
dpkg --list|grep mysql
将其中包含的包全部删除
sudo apt-get remove ‘包名’
sudo apt-get autoremove --purge mysql-server-*
清理残留
dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P
再检查依赖是否全部删除
之后使用 whereis mysql 找到相干文件一并删除