MySQL 安装、配置、卸载

1. 安装

1
2
sudo apt update
sudo apt install mysql-server

2. 配置

1
sudo mysql_secure_installation

检查服务状态

1
systemctl status mysql.service

root 登录

1
sudo mysql -uroot -p

(可选) 设置密码

1
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";

3. 新建数据库和用户

1
2
CREATE DATABASE jitd;
GRANT ALL PRIVILEGES ON jitd.* TO dbuser@localhost IDENTIFIED BY "654321";

设置允许远程访问

1
GRANT ALL PRIVILEGES ON jitd.* TO dbuser@"%" IDENTIFIED BY "654321";
1
2
3
4
sudo vim /etc/mysql/my.cnf

##在最后添加如下配置,允许其他机器访问MySQL
>skip-networking => # skip-networking

4. 完全卸载

1
2
3
sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge