php無法連至mysql? (error code: 1045) - Linux

Table of Contents

※ [本文轉錄自 PHP 看板 #1CtMGwyS ]

作者: Aligu1009 (=.=) 看板: PHP
標題: [請益] php無法連至mysql?
時間: Fri Nov 12 23:58:48 2010

我在RH Linux 上用source 安裝 Apache MySQL PHP 至我自己的家目錄下
(因為我沒有管理者權限)

目前apache + php可正常使用,直接在shell 下用mysql -uusername -p
也可以正常的連上資料庫

問題:當我從php中用
$con = mysql_connect("localhost","username","password") or
die ("cannot find server: " . mysql_error());

卻會得到
Warning: mysql_connect() [function.mysql-connect]: Access denied for user
'username'@'localhost' (using password: YES) in
/home/sean/share/apache2/htdocs/dev/init_db.php on line 2
cannot find server: Access denied for user 'username'@'localhost' (using
password: YES)

我已用mysql的root帳號嚐試過以下的五種解法,但結果都一樣:

GRANT SELECT, INSERT, UPDATE, DELETE, LOCK TABLES ON dbname.* TO
[email protected] IDENTIFIED by 'password';

GRANT SELECT, INSERT, UPDATE, DELETE, LOCK TABLES ON dbname.* TO
username@localhost IDENTIFIED by 'password';

SET PASSWORD FOR [email protected]=PASSWORD('password');

SET PASSWORD FOR username@localhost=PASSWORD('password');

FLUSH privileges;

----
另外,我為了搞清楚到底是PHP的問題還是MySQL的問題,
我用python寫了一小段程式access mysql資料庫,同樣發生exception:
"Access denied for user 'username'@'localhost' (using password: YES)"

有人有經驗能分享嗎?任何建議 (在我的帳號權限範圍內) 我都能試試看

--

All Comments

Elvira avatarElvira2010-11-15
試看看用 OLD_PASSWORD
Enid avatarEnid2010-11-19
感覺是mysql的問題,你是在哪台機器登入mysql?
George avatarGeorge2010-11-22
你先grant all on *.*這樣的權限試試看。