ERROR 1045 (28000)


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 Denial

3/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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章