卸載
1 sudo apt-get autoremove --purge mysql-server-5.7 2 sudo apt-get remove mysql-server 3 sudo apt-get autoremove mysql-server 4 sudo apt-get remove mysql-common 5 sudo rm -rf /etc/mysql/ /var/lib/mysql #很重要 6 #清理殘留數據 7 dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 8 sudo apt autoremove 9 sudo apt autoclean
安裝
1 sudo apt-get install mysql-server 2 sudo apt-get install mysql-client 3 sudo apt-get install libmysqlclient-dev
使用:
1.啟動服務(我看好多教程都是sudo service mysql start,但是我這不好使)
1 sudo /etc/init.d/mysql start
2.登錄(我走的流程)(這里在登陸的時候發現不輸入密碼無法登陸,但是安裝過程中也沒有輸入密碼這一步,查找資料后發現需要自己查看用戶名密碼,登陸進去以后在修改root密碼)
2.1.查看可以登錄的用戶名密碼
1 sudo cat /etc/mysql/debian.cnf
2.2.記住里面的user和password對應的值,然后進行登錄
1 mysql -u user -p 2 #輸入密碼
2.3.在MySQL 5.7 中 password字段已從mysql.user表中刪除,新的字段名是“authenticalion_string”.
先檢查一下root 的 plugin字段是否為mysql_native_password
use mysql; select user, plugin from user;
這是我現在的值(開始的時候我的root的plugin字段就是’auth_socket‘ 修改語句“
update user set plugin='mysql_native_password' where user='root';
”)
+------------------+-----------------------+ | user | plugin | +------------------+-----------------------+ | root | mysql_native_password | | mysql.session | mysql_native_password | | mysql.sys | mysql_native_password | | debian-sys-maint | mysql_native_password | +------------------+-----------------------+
2.4修改密碼
update user set authentication_string=password('newPwd') where user='root';
flush privileges; #刷新mysql權限
3.新密碼登錄
1 mysql -u root -p 2 #輸入密碼即可
4.可視化界面安裝(workbench)
1 sudo apt-get install mysql-workbench
命令行輸入mysql-workbench就可以啟動
參考文章:
https://www.cnblogs.com/leolztang/p/5094930.html
https://blog.csdn.net/hs_2017/article/details/79165762 (這篇文章中刷新mysql權限的語句有錯誤,注意下)