Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Background info

I'm currently running CentOS (or Red Hat?).

uname -a gives (I edited out my domain name)

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 gives

CentOS release 6.2 (Final)
Kernel \r on an \m

and `cat /proc/version' gives

Linux version 2.6.32-71.29.1.el6.x86_64 (mockbuild@c6b5.bsys.dev.centos.org) (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 gives

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 gives

mysql  Ver 14.14 Distrib 5.5.20, for Linux (x86_64) using readline 5.1

python --version gives

Python 2.7.2

I also know python is 64-bit because math.log( sys.maxsize, 2 ) + 1 returns 64.

Originally I believe PHP could communicate with MySQL when I installed MySQL over yum, but that is version 5.1 and I wanted 5.5 (better InnoDB features). So I uninstalled MySQL 5.1 with yum then manually installed 5.5 using most of this guide.

I can enter the MySQL monitor (CLI tool) and do everything such as create databases and tables and enter queries.

Problem

But when I try to interact MySQL with PHP. I get the following error:

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

During the installation of MySQLdb for Python, I get this error message:

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

Possible useful info

Part of /etc/my.cnf reads

# 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

Part of /etc/php.ini reads

[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

Both the my.cnf and php.ini read /var/lib/mysql/mysql.sock. What is wrong with my configuration?? Thanks in advance for reading this long post!

Edit

Here are some new information:

/var/lib/mysql shows the following content (once again I X'ed out my domain name):

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'; gives

+---------------+---------------------------+
| Variable_name | Value                     |
+---------------+---------------------------+
| socket        | /var/lib/mysql/mysql.sock |
+---------------+---------------------------+
1 row in set (0.00 sec)

which gcc gives

/usr/bin/gcc

gcc --version gives

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 gives

/usr/lib64/mysql/libmysqlclient_r.so.16
/usr/lib64/mysql/libmysqlclient_r.so.16.0.0
/usr/lib64/mysql/libmysqlclient_r.a

So this looks like MySQLdb was looking in the wrong path (lib instead of lib64)?

share|improve this question
    
Just a thought: does /var/lib/mysql/mysql.sock exist? –  Herman Torjussen Feb 7 '12 at 8:35
    
...and if so what's the permissions? Also what does SHOW VARIABLES LIKE 'socket'; report? Are you using the same username to connect using the mysql cli as php? –  symcbean Feb 7 '12 at 14:13
    
And for python question does libmysqlclient_r.* exist on the system? And if so is it in the library search path for gcc? –  Karlson Feb 7 '12 at 14:25
    
Hey guys, thanks for the response. I think after searching for libmysqlclient_r.*, I realize maybe MySQLdb is looking for the 32-bit installation of MySQL and I have the 64-bit. But I still have no clue on the PHP and MySQL problem with the socket. –  hobbes3 Feb 7 '12 at 16:55
    
a quick way to fix your python build problem : export LD_LIBRARY_PATH=/usr/lib64/mysql and relaunch your python build. –  Coren Feb 8 '12 at 8:05
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.