1. 程式人生 > >ubuntu16.04安裝和解除安裝MySQL5.7

ubuntu16.04安裝和解除安裝MySQL5.7

一. 安裝MySQL
1. 安裝前先更新軟體包列表:(不是必須的)

 $ sudo apt update

2. 在Ubuntu 16.04上安裝MySQL:

 $ sudo apt-get install mysql-server

3.在安裝過程中需要你輸入MySQL 管理員使用者(root)密碼

二.資料庫的基本使用
1.使用root使用者登入:
$ mysql -u root -p

2.停止MySQL資料庫服務:
$ sudo systemctl stop mysql.service

3.啟動MySQL資料庫服務:
$ sudo systemctl start mysql.service

4.重啟MySQL資料庫服務:
$ sudo systemctl restart mysql.service

5.檢視MySQL執行狀態:
$ sudo systemctl status mysql.service

6.MySQL的配置文:
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

三. 安裝mysql-workbench
因為前面已經安裝了MySQL,所以直接輸入sudo apt-get install mysql-workbench即可安裝mysql-workbench。

四. 設定禁止mysql開機自啟動(apt-get安裝的mysql預設是開機自啟動的)
1.執行命令:
sudo update-rc.d mysql disable
2.重啟生效:
sudo reboot

五. 刪除 mysql

sudo apt-get autoremove –purge mysql-server-5.0
sudo apt-get remove mysql-server
sudo apt-get autoremove mysql-server
sudo apt-get remove mysql-common //這個很重要
上面的其實有一些是多餘的。
清理殘留資料

dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P