一镶骗、安裝
sudo apt update?
sudo apt-get install mysql-server? # 安裝MySQL服務(wù)端
以上兩個命令 即安裝成功
二近迁、安裝后的密碼問題
sudo cat /etc/mysql/debian.cnf 查看默認的用戶名和密碼
三倍宾、添加自己的密碼
1蔬捷、use mysql; 然后敲回車
2幔翰、update user set authentication_string=password("你的密碼") where user="root"; 然后敲回車
3凭疮、flush privileges; 然后敲回車
用賬戶密碼登錄時發(fā)現(xiàn)報錯
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
解決方法如下:
step1:在ubuntu的terminal(也即終端)上輸入:
? ??????sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf,
????????進入到這個配置文件,
????????然后在這個配置文件中的[mysqld]這一塊中加入skip-grant-tables這句話膛腐。
? ??????保存:wq睛约,退出。輸入:service mysql restart哲身,重新啟動mysql辩涝。
step2:在終端上輸入mysql -u root -p,遇見輸入密碼的提示直接回車即可,進入mysql后勘天,分別執(zhí)行下面三句話:
????????1怔揩、use mysql; 然后敲回車
????????2棍丐、update user set authentication_string=password("你的密碼") where user="root"; 然后敲回車
????????3、flush privileges; 然后敲回車
step3:重新進入到mysqld.cnf文件中去把剛開始加的skip-grant-tables這條語句給注釋掉沧踏。
????????????再返回終端輸入mysql -u root -p,應(yīng)該就可以進入數(shù)據(jù)庫了巾钉。
step4:如果此時還是報出錯誤翘狱,那么就需要返回step3中,把注釋掉的那條語句重新生效(就是刪除#符號)砰苍,重新進入mysql中潦匈,先選擇一個數(shù)據(jù)庫(use mysql;),然后輸入select user,plugin from user;,看下圖:
從圖中可以看到在執(zhí)行了select user,plugin from user;后赚导,錯誤原因是因為plugin root的字段是auth_socket茬缩,那我們改掉它為下面的mysql_native_password就行了。輸入:
1吼旧、update user set authentication_string=password("你的密碼"),plugin='mysql_native_password' where user='root';
最后quit退出凰锡。返回執(zhí)行step3。
那么這個問題就完全解決了