0

我正在使用 PHP 以通过以下方式连接到 MySQL:

$link = mysql_connect('...host...', '...username...', '...password...'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
echo 'Connected successfully'; 

它连接得很好。但是当从我的终端尝试时

mysql -h ...host... -u ....username... -p ...password...

我给了我的密码,结果是:

ERROR 2003 (HY000): Can't connect to MySQL server on '...host...' (111)

有什么想法可以解决这个问题吗?

4

2 回答 2

0

The php code is running on the web server, your local command is running on your machine.

MySQL accounts are not just usernames - they are username + hostname combos. So both have to match for MySQL to find the account.

Since your hostname is different from the one the web server uses MySQL does not consider it a valid user. (It's possible to set the hostname to % which means "Any".)

于 2011-07-18T03:54:54.197 回答
0

尝试 sudo mysql -h ....etc。

我正在运行 linuxMint 并且必须使用 su 或 sudo。我认为默认情况下你必须是 root 才能进入终端。但是无法访问 Ubuntu 根目录,这是我不喜欢 Ubuntu 的唯一功能。

于 2011-07-18T03:39:28.520 回答