Access denied for user: '@unknown' to database mysql
這意味著,你沒有一個條目在user表中的一個User列值為'root'並且mysqld不能為你的客庫解析主機名。在這種情況下,你必須用--skip-grant-tables選項重啟服務器並且編輯你的“/etc/hosts”或“\windows\hosts”文件為你的主機增加一個條目。
http://hi.baidu.com/redflower1004/blog/item/23387c179318c604c93d6d97.html
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
#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中的默认值)
症狀:
使用 synaptic 安裝 mysql 後,呼叫 mysql_install_db 初始化後,想透過 SHELL> mysql -u root 登入,建立密碼,卻出現 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO),即使想透過 mysql -u root -p ,強制輸入密碼,仍一樣出錯,只是錯誤變成 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:YES)
解決方法[3]:
- 先關閉 mysql daemon
- 以 --skip-grant-tables 喚起 mysql daemon ,如:mysqld --skip-grant-tables
- 這時應當可透過以下指令登入:mysql -u root mysql
- 利用 mysql 指令修改使用者密碼。
- mysql> UPDATE user SET Password=PASSWORD('your_new_password') where USER='root';
mysql> FLUSH PRIVILEGES; - 關閉 mysql daemon 後,再正常啟動。
- 似乎之後新增 database user 也需透過這個方法。
參考資料:
- MySQL Manual 2.10.3. Securing the Initial MySQL Accountshttp://dev.mysql.com/doc/refman/4.1/en/default-privileges.html
- 鳥哥的 Linux 私房菜 http://linux.vbird.org/
- MySQL Forum http://forums.mysql.com/read.php?11,34014,46593#msg-46593
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。