我无法通过php连接到mysql。在执行mysql_connect()
函数时,apache错误日志中会产生[error] [client 127.0.0.1] PHP Warning: mysql_connect(): No such file or directory
错误消息。
请查找运行php -m
命令时的警告消息:
$ php -m | grep mysql
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll, 9): image not found in Unknown on line 0
mysql
mysqli
mysqlnd
pdo_mysql
并且
$ mysqladmin -h `hostname` --port=3306 version
/usr/local/mysql/bin/mysqladmin: connect to server at 'heapzero.local' failederror: 'Host '192.168.1.36' is not allowed to connect to this MySQL server'
PHP 版本:
$ php --version
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/msql.so, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysql.dll, 9): image not found in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/php_mysqli.dll, 9): image not found in Unknown on line 0
PHP 5.3.2 (cli) (built: Aug 7 2010 00:04:41)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
MySQL版本:
mysql --version
/usr/local/mysql/bin/mysql Ver 14.14 Distrib 5.1.50, for apple-darwin10.3.0 (i386) using readline 5.1
我花了很多时间来修复这个问题。请提供建议!谢谢!
$ mysqladmin -h \
hostname` --port=3306 version` 在Snow Leopard上对我来说很好用,但是我的MySQL版本比你低(5.0.51),尽管我使用的是最新的OSX(10.6.4)。 - Matt Gibson