看板 PHP 關於我們 聯絡資訊
我在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 username@127.0.0.1 IDENTIFIED by 'password'; GRANT SELECT, INSERT, UPDATE, DELETE, LOCK TABLES ON dbname.* TO username@localhost IDENTIFIED by 'password'; SET PASSWORD FOR username@127.0.0.1=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)" 有人有經驗能分享嗎?任何建議 (在我的帳號權限範圍內) 我都能試試看 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 75.102.80.84
buganini:mysql version? client library version? 11/13 02:22
buganini:cli php跑起來如何呢? 11/13 02:22
averywu:try mysql_connect("",$uname,$pass); 11/14 19:41
buganini:看mysql的log 11/14 20:03