背景信息
我目前正在运行 CentOS(或 Red Hat?)。
uname -a
给出(我编辑了我的域名)
Linux XXXXXXXXX.com 2.6.32-71.29.1.el6.x86_64 #1 SMP Mon Jun 27 19:49:27 BST 2011 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/issue
给出
CentOS release 6.2 (Final)
Kernel \r on an \m
和 `cat /proc/version' 给出
Linux version 2.6.32-71.29.1.el6.x86_64 ([email protected]) (gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) ) #1 SMP Mon Jun 27 19:49:27 BST 2011
php --version
给出
PHP 5.3.3 (cli) (built: Jan 11 2012 19:53:01)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
mysql --version
给出
mysql Ver 14.14 Distrib 5.5.20, for Linux (x86_64) using readline 5.1
python --version
给出
Python 2.7.2
我也知道 python 是 64 位的,因为math.log( sys.maxsize, 2 ) + 1
返回64
.
最初我相信当我安装 MySQL 时 PHP 可以与 MySQL 通信yum
,但那是版本 5.1,我想要 5.5(更好的 InnoDB 功能)。所以我卸载了 MySQL 5.1,yum
然后使用其中的大部分手动安装了 5.5指导。
我可以进入 MySQL 监视器(CLI 工具)并执行所有操作,例如创建数据库和表以及输入查询。
问题
但是当我尝试用 PHP 交互 MySQL 时。我收到以下错误:
Not connected : Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
在安装 MySQLdb for Python 期间,我收到以下错误消息:
root@XXXXXXXXX:/usr/local/MySQL-python-1.2.3# python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/local/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -m64 -fPIC -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:422:1: warning: "HAVE_WCSCOLL" redefined
In file included from /usr/local/include/python2.7/Python.h:8,
from pymemcompat.h:10,
from _mysql.c:29:
/usr/local/include/python2.7/pyconfig.h:887:1: warning: this is the location of the previous definition
gcc -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib64 -lmysqlclient_r -lpthread -lm -lrt -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
可能有用的信息
部分/etc/my.cnf
读物
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
部分/etc/php.ini
读物
[MySQL]
; Allow or prevent persistent links.
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.allow-persistent
mysql.allow_persistent = On
; Maximum number of persistent links. -1 means no limit.
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.max-persistent
mysql.max_persistent = -1
; Maximum number of links (persistent + non-persistent). -1 means no limit.
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.max-links
mysql.max_links = -1
; Default port number for mysql_connect(). If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order). Win32 will only look
; at MYSQL_PORT.
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.default-port
mysql.default_port =
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.default-socket
mysql.default_socket = /var/lib/mysql/mysql.sock
; Default host for mysql_connect() (doesn't apply in safe mode).
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.default-host
mysql.default_host =
; Default user for mysql_connect() (doesn't apply in safe mode).
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.default-user
mysql.default_user =
; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password! And of course, any users with read access to this
; file will be able to reveal the password as well.
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.default-password
mysql.default_password =
; Maximum time (in seconds) for connect timeout. -1 means no limit
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.connect-timeout
mysql.connect_timeout = 60
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
; http://www.php.net/manual/en/mysql.configuration.php#ini.mysql.trace-mode
mysql.trace_mode = Off
my.cnf
和php.ini
read都可以/var/lib/mysql/mysql.sock
。我的配置有什么问题吗?预先感谢您阅读这篇长文!
编辑
以下是一些新信息:
/var/lib/mysql
显示以下内容(我再次删除了我的域名):
total 29M
drwx------ 6 mysql 4.0K Feb 2 13:25 ./
drwxr-xr-x. 52 root 4.0K Sep 23 07:50 ../
-rw-rw---- 1 mysql 18M Feb 2 15:04 ibdata1
-rw-rw---- 1 mysql 5.0M Feb 2 15:04 ib_logfile0
-rw-rw---- 1 mysql 5.0M Feb 2 12:03 ib_logfile1
drwx------ 2 mysql 4.0K Feb 2 15:04 mapshare/
drwx------ 2 mysql 4.0K Feb 2 11:20 mysql/
-rw-rw---- 1 mysql 906 Feb 2 12:58 mysql-bin.000001
-rw-rw---- 1 mysql 1.9K Feb 2 15:04 mysql-bin.000002
-rw-rw---- 1 mysql 38 Feb 2 12:59 mysql-bin.index
srwxrwxrwx 1 mysql 0 Feb 2 12:59 mysql.sock
drwx------ 2 mysql 4.0K Feb 2 11:20 performance_schema/
-rw-r--r-- 1 mysql 678 Feb 2 12:01 RPM_UPGRADE_HISTORY
-rw-r--r-- 1 mysql 339 Feb 2 12:01 RPM_UPGRADE_MARKER-LAST
-rw-rw---- 1 mysql 3.0K Feb 2 12:59 XXXXXXXXXX.err
-rw-rw---- 1 mysql 6 Feb 2 12:59 XXXXXXXXXX.pid
drwx------ 2 mysql 4.0K Feb 2 13:35 scoutmob/
show variables like 'socket';
给出
+---------------+---------------------------+
| Variable_name | Value |
+---------------+---------------------------+
| socket | /var/lib/mysql/mysql.sock |
+---------------+---------------------------+
1 row in set (0.00 sec)
which gcc
给出
/usr/bin/gcc
gcc --version
给出
gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
find / -name libmysqlclient_r.* 2>/dev/null
给出
/usr/lib64/mysql/libmysqlclient_r.so.16
/usr/lib64/mysql/libmysqlclient_r.so.16.0.0
/usr/lib64/mysql/libmysqlclient_r.a
所以这看起来 MySQLdb 正在寻找错误的路径(lib
而不是lib64
)?