通过 apt-get 安装
sudo apt-get update
sudo apt-get install mysql-server
使用 debian-sys-maint 的账户密码登录
cat /etc/mysql/debian.cnf
mysql -u debian-sys-maint -p
修改root账户密码
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT `Host`, `user`, `plugin` from `user` WHERE user = "root";
+-----------+------------------+-----------------------+
| Host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | root | mysql_native_password |
+-----------+------------------+-----------------------+
1 rows in set (0.00 sec)
mysql> exit;
卸载MySQL
查看MySQL依赖
root@scolint:~
ii mysql-client-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL database client binaries
ii mysql-client-core-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL database core client binaries
ii mysql-common 5.8+1.0.8 all MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-server 8.0.34-0ubuntu0.22.04.1 all MySQL database server (metapackage depending on the latest version)
ii mysql-server-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL database server binaries and system database setup
ii mysql-server-core-8.0 8.0.34-0ubuntu0.22.04.1 amd64 MySQL database server binaries
卸载MySQL
apt-get autoremove --purge mysql-server-8.0
apt-get remove mysql-common
清除残余文件
dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P
删除剩余依赖项
apt-get autoremove --purge xxx
最后删除mysql的目录
rm -rf /etc/mysql/ /var/lib/mysql