当我尝试通过远程 MySQL 服务器上的本地计算机的 shell 进行连接时,我可以成功连接:
> mysql -h remotehost -u myuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
但是当我尝试使用 PHP 脚本连接时
$serverName = "remotehost"; // here I put the actual IP address
$userName = "myuser";
$passCode = "actualpassword";
mysql_connect($serverName,$userName,$passCode);
我收到以下错误
警告:mysql_connect():用户“myuser”@“localhost”的访问被拒绝(使用密码:是)
远程MySQL服务器版本为5.1.52,本机PHP版本为5.3.10-1ubuntu3.4
我发现了一个类似的问题,但答案并没有解决我的问题: problem connected to remote mysql database using php
我真的很感激一些帮助!
编辑:
的输出 php -i | grep "mysql"
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/mysqli.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini
mysql
MYSQL_SOCKET => /var/run/mysqld/mysqld.sock
MYSQL_INCLUDE => -I/usr/include/mysql
MYSQL_LIBS => -L/usr/lib/i386-linux-gnu -lmysqlclient_r
mysql.allow_local_infile => On => On
mysql.allow_persistent => On => On
mysql.connect_timeout => 60 => 60
mysql.default_host => no value => no value
mysql.default_password => no value => no value
mysql.default_port => no value => no value
mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
mysql.default_user => no value => no value
mysql.max_links => Unlimited => Unlimited
mysql.max_persistent => Unlimited => Unlimited
mysql.trace_mode => Off => Off
mysqli
MYSQLI_SOCKET => /var/run/mysqld/mysqld.sock
mysqli.allow_local_infile => On => On
mysqli.allow_persistent => On => On
mysqli.default_host => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_pw => no value => no value
mysqli.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
mysqli.default_user => no value => no value
mysqli.max_links => Unlimited => Unlimited
mysqli.max_persistent => Unlimited => Unlimited
mysqli.reconnect => Off => Off
PDO drivers => mysql
pdo_mysql
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock