배경 정보
저는 현재 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
math.log( sys.maxsize, 2 ) + 1
을 반환하기 때문에 Python이 64비트라는 것도 알고 있습니다 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)
Python용 MySQLdb를 설치하는 동안 다음 오류 메시지를 받았습니다.
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
)?