解決Mysql ERROR 1045 (28000): Access denied for user ‘root’@’localhost’問題

來源:互聯網
上載者:User
 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) Red Hat Enterprise Linux 5伺服器上mysql啟動報錯:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
原因1-啟動命令錯誤:
我開始的時候直接輸入命令:mysql start
正確的啟動命令是: /etc/rc.d/init.d/mysql start

原因2-設定檔錯誤:
檢查etc下面的my.cnf如下內容:[client]
#password   = your_password
port     = 3306
socket     = /usr/mysql-data/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port     = 3306
socket     = /usr/mysql-data/mysql.sock

原因3-開機檔案錯誤:
需要修改MySQL啟動指令碼/etc/rc.d/init.d/mysql,
其中datadir=   ?     一行檢查下!

原因4-前提是你在使用php串連時候報錯!
在/etc/php.ini修改mysql.default_socket的值設定為:
mysql.default_socket=/var/lib/mysql/mysql.sock
回到終點設定個串連:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
(在/etc/php.ini中mysql.default_socket這個檔案中,關於mysql.default_socket的值的說明是這樣的,
;Default socket name for local MySQL connects. If empty, uses the built-in MySQL defaults.
這個值一開始是空的,也就是說,如果我們不主動去修改的話,php將會使用內建在mysql中的預設值)

 另一篇文章:Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'問題的解決

這種問題需要強行重新修改密碼,方法如下:

/etc/init.d/mysql stop   (service mysqld stop )
/usr/bin/mysqld_safe --skip-grant-tables
另外開個SSH串連
[root@localhost ~]# mysql
mysql>use mysql
mysql>update user set password=password("123456") where user="root";
mysql>flush privileges;
mysql>exit

pkill -KILL -t pts/0 可將pts為0的**使用者(之前運行mysqld_safe的使用者視窗)強制踢出
正常啟動 MySQL:/etc/init.d/mysql start   (service mysqld start)

注意:另外還遇到需要service mysql star才能啟動service mysql stop才能停止。
還有直接使用mysql不能找到命令,錯誤為“bash: mysql: command not found”可以直接**mysql的安裝目錄中的bin檔案夾跟絕對路徑運行命令,還有的需要加./mysql 才能執行。 本文來自:http://sundful.javaeye.com/blog/704337 另一篇關於清除密碼、重設使用者的文章: 

Quote:
First things first. Log in as root and stop the mysql daemon.

sudo /etc/init.d/mysql stop

Now lets start up the mysql daemon and skip the grant tables which store the passwords.

sudo mysqld_safe --skip-grant-tables&

(press Ctrl+C now to disown the process and start typing commands again)

You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.

sudo mysql --user=root mysql

update user set Password=PASSWORD('new-password');
flush privileges;
exit;

Now kill your running mysqld then restart it normally.

sudo killall mysqld_safe&
(press Ctrl+C now to disown the process and start typing commands again)
/etc/init.d/mysql start

You should be good to go. Try not to forget your password again.

http://www.howtoforge.com/reset-forgotten-mysql-root-password  另外關於denied的總結:MySQL Authentication Denial3/29/2005, 12:05 am

It seems to me that a lot of people have auth denial when trying to make connections to MySQL. They seem to ignore the text of the error message. ‘Access Denied’ means access denied, nothing else.

Remember three things have to match. The host as MySQL sees it, the username, and the password. When MySQL returns access denied it’s not broken. One or more of those three things does not match. I don’t really need to reiterate what’s in the manual. Chang the lock or change the key to make it fit.

其中串連到mysql的文檔內容為:http://dev.mysql.com/doc/refman/5.5/en/access-denied.html  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.