MySQLソケットとPHP(およびその他の言語)

MySQLソケットとPHP(およびその他の言語)

背景情報

私は現在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.cnfphp.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)?

ベストアンサー1

おすすめ記事