socket MySQL e PHP (e outras linguagens)

2

Informações de plano de fundo

Atualmente estou executando o CentOS (ou Red Hat?).

uname -a dá (editei meu nome de domínio)

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

e 'cat / proc / version' dá

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

Eu também sei que o python é de 64 bits porque math.log( sys.maxsize, 2 ) + 1 retorna 64 .

Originalmente acredito que o PHP poderia se comunicar com o MySQL quando eu instalei o MySQL sobre yum , mas essa é a versão 5.1 e eu queria 5.5 (melhores características do InnoDB). Então, eu desinstalei o MySQL 5.1 com yum e depois instalei manualmente o 5.5 usando a maior parte deste guia .

Eu posso entrar no monitor do MySQL (ferramenta CLI) e fazer tudo como criar bancos de dados e tabelas e inserir consultas.

Problema

Mas quando eu tento interagir o MySQL com PHP. Eu recebo o seguinte erro:

Not connected : Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

Durante a instalação do MySQLdb para Python, recebo esta mensagem de erro:

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

Informações úteis possíveis

Parte de /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

Parte de /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

Tanto o my.cnf quanto o php.ini leem /var/lib/mysql/mysql.sock . O que há de errado com minha configuração? Agradecemos antecipadamente por ler este longo post!

Editar

Aqui estão algumas informações novas:

/var/lib/mysql mostra o conteúdo a seguir (mais uma vez eu tirei meu nome de domínio):

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

Então, parece que o MySQLdb estava procurando no caminho errado ( lib em vez de lib64 )?

    
por hobbes3 07.02.2012 / 07:43

0 respostas