今天在換了Ubuntu后裝個本地的mysql,安裝過程沒什么好說的:sudo apt-get install mysql-server
安裝好了之后我做了以下一系列常規動作:
1.$sudo mysql -----------進入mysql
2.grant all privileges on *
.* to 'root'@'localhost' identified by 'xxxx' ---------------------賦權設密碼
3.exit
4.mysql -u root -p xxxx ---------------通過用戶密碼登錄
此時問題來了:ERROR 1698 (28000): Access denied for user 'root'@'localhost
好吧,一波常規檢查:
1.ping xx.xxx.xx -----------檢查網絡
2.nmap xx.xxx.xx -----------------檢測端口是否開放
一切正常。。。。。。繼續
3.$sudo mysql ---------------通過root權限進入mysql
4.select user,host,password from user; ------------------查看下用戶表
問題來了:password 字段不存在。。。 百度一番(authentication_string 替換了password)
5.select user,host,authentication_string from user; -----------------再次查看用戶表
此時會發現root賬號下沒有密碼!!!(回過頭看看,之前我似乎設置了密碼的~)繼續!
6.select user,host,authentication_string,plugin from user; ---------------------再次仔細查看用戶表!
此時有所發現:root下plugin 為auth_socket 而非:mysql_native_password
問題找到了,那么接下來我們有2中改法:
1.修改這個值
2.新建一個用戶作為登錄用戶,並給予所有權限
在實際處理中出於安全性考慮,我選擇了新建一個用戶的方式:grant all privileges on *
.* to 'xxx'@'localhost' identified by 'xxxx' ;
做完上述操作后,退出mysql
然后使用:mysql -u xxx -p xxxx -------------------成功進入!(問題解決)