安装MySQL8
安装mysql-server sudo apt install mysql-server
初始化配置信息 sudo mysql_secure_installation
VALIDATE PASSWORD COMPONENT…(使用密码强度校验组件) 输入: n
New Password:(设置新密码,并重复一遍)
Remove anonymous users (删除匿名用户) n
Disallow root login remotely(拒绝远程root账号登录) n
Remove test database and access to it(移除test数据库) n
Reload privilege tables now (现在就重新载入权限表) y
解决 操作系统非root用户登录报错:ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’
sudo mysql -uroot -p
配置root用户外网也可以连接并登录
use mysql
select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | auth_socket |
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '$pass';
FLUSH PRIVILEGES;
# 刷新权限
select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | debian-sys-maint | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
再次登录:
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
MySQL8 卸载
查看MySQL依赖 : dpkg --list|grep mysql
卸载: sudo apt-get remove mysql-common
卸载: sudo apt-get autoremove --purge mysql-server-8.0
(这里版本对应即可)
清除残留数据: dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P
再次查看MySQL的剩余依赖项: dpkg --list|grep mysql
(这里一般就没有输出了,如果有执行下一步)
继续删除剩余依赖项,如:sudo apt-get autoremove --purge mysql-apt-config
在执行过程中有的需要sudo