首先是不知道怎么忽然mysql用命令列,workbench都登錄不了,都提示'Access denied for user 'root'@'localhost',
資料庫卸載重裝了幾次都不行,好像感覺資料清理不干凈,解決的程序遇到的坑,這里記錄分享下,
有效的操作記錄下:
1、首先是跳過權限登錄mysql,查看user表,
停止mysql服務~$ sudo service mysql stop
以安全模式啟動MySQL~$ sudo mysqld_safe --skip-grant-tables
注意:
可能提示mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exist
解決方法:(筆者嘗試發現必須加sudo)
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
再次執行上面安全模式啟動mysql ~$ sudo mysqld_safe --skip-grant-tables
這次提示陳述句顯示了,mysqld_safe Staring mysqld deamon with database from /var/lib/mysql
用 ctrl + z結束上面的執行
特例:
(如果這里提示: mysqld_safe A mysqld process already exists, 解決方法如下:sudo netstat -anpl | grep :3306)

這次登錄可以不用密碼:mysql -u root 回車就登錄了
sql陳述句查詢mysql.user表的情況,如下:


還有人提議如下這么做,沒嘗試
Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
Add skip-grant-tables under [mysqld]
2、發現user的plugin為socket_plugin,改為mysql_native_password
修改root的plugin權限:
update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
flush privileges;
quit;
(注意這里修改一定要正確,免得跟筆者一樣,粗心的把plugin修改的內容少些了一個字母,又有下面的折騰)
3、user表還有其他用戶,root不能登錄,用其他的用戶登錄也行啊,查詢了發現一下有效操作:
在mysql的安裝目錄,一般在 /etc/mysql里面有個debain.cnf檔案,里面有user,password,用這個用了登錄,密碼最后復制,然后就又可以修改user表root的plugin,操作同上,
重啟mysql服務, sudo service mysql restart;
用root用戶就可以登錄,
參考博客:
MySQL ERROR 1698 (28000) 錯誤 https://www.cnblogs.com/leolztang/p/5094930.html
mysql 查看當前使用的組態檔my.cnf的方法 https://blog.csdn.net/fdipzone/article/details/52705507
linux -- Ubuntu查看修改mysql的登錄名和密碼、安裝phpmyadmin https://www.cnblogs.com/hf8051/p/4775627.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/101303.html
標籤:MySQL
上一篇:請教多表查詢的實作方法
下一篇:MySQL資料庫多表查詢
