一、安装
下载安装
sudo apt install mysql-server -y
查看版本
mysql --version
mysql Ver 8.0.33-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))
查看是否运行
sudo systemctl status mysql
Active: active (running) since Thu 2023-05-18 19:53:54 CST; 2h 41min ago
修改密码
进入mysql(默认无密码)
sudo 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
查看
select host,user from user;
返回结果:
±----------±-----------------+
| host | user |
±----------±-----------------+
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
±----------±-----------------+
5 rows in set (0.26 sec)
改为可从任何主机访问数据库
update user set host='%' where user='root';
返回结果:
Query OK, 1 row affected (0.22 sec)
Rows matched: 1 Changed: 1 Warnings: 0
查看
select host,user from user;
返回结果:
±----------±-----------------+
| host | user |
±----------±-----------------+
| % | root |
| localhost | debian-sys-maint |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
±----------±-----------------+
5 rows in set (0.00 sec)
改密码
show databases;
show tables;
select host,user from user;
alter user 'root'@'%' identified with mysql_native_password by 'master$12342023';
flush privileges;
退出
exit
测试登录
mysql -u root -p 123456
退出
exit
开启远程访问
改
vim /etc/mysql/mysql.conf.d/mysqld.cnf
将以下地址均改为 0.0.0.0
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
重启mysql
sudo systemctl restart mysql
测试:使用navicat连接
二、卸载
使用 apt-get 命令卸载 MySQL:
sudo apt-get remove --purge mysql-server mysql-client mysql-common
删除 MySQL 的配置文件和数据:
sudo rm -rf /etc/mysql/ /var/lib/mysql/
清除 MySQL 相关的依赖:
sudo apt-get autoremove
清除残留文件和目录:
sudo find / -iname 'mysql*' -exec rm -rf {} ;
参考: unbuntu如何彻底删除mysql?
————————————————