1、安裝MySQL
a、安裝服務端
sudo apt-get install mysql-server
b、設置root用戶
sudo passwd
c、安裝客戶端
sudo apt-get install mysql-client
d、查看MySQL是否安裝成功
sudo netstat -tap | grep mysql
2、配置遠程訪問
a、編輯配置文件
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 將bind-address = 127.0.0.1注釋
b、修改用戶權限
登錄MySQL:mysql -u root -p --遠程訪問 mysql -h 192.168.0.201 -P 3306 -u root -p123 123為root用戶密碼
用戶權限:grant all on *.* to root@'%' identified by '1'; --添加一個用戶名是root且密碼是1的遠程訪問用戶
刷新:flush privileges;
查看是否添加成功:select user,host,authentication_string from user; --在5.7中用戶密碼是列authentication_string
退出:quit
c、重啟MySQL服務
/etc/init.d/mysql restart
3、完成且測試通過。
ps:
附上vi編輯要點:點擊i進入編輯模式,在按esc鍵輸入:wq!(保存並退出vi編輯模式)
MySQL卸載:
1、sudo apt-get autoremove --purge mysql-server-5.0
2、sudo apt-get remove mysql-server
3、sudo apt-get autoremove mysql-server
4、sudo apt-get remove mysql-common --這個很重要
5、dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P -- 清除殘留數據