Solve PDO problem when installing Drupal 7 in Mac OS X Snow Leopard 10.6.5

When you install Drupal 7 in Mac OS X Snow Leopard, somehow you get problem about PDO MySQL like this error ?

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in DatabaseConnection->__construct() (line 289 of /Users/drupal7/includes/database/database.inc).



In order for Drupal to work, and to continue with the installation process, you must resolve all issues reported below. For more help with configuring your database server, see the installation handbook. If you are unsure what any of this means you should probably contact your hosting provider.
Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] No such file or directory.

Is the database server running?
Does the database exist, and have you entered the correct database name?
Have you entered the correct username and password?
Have you entered the correct database hostname?

This happen because you have invalid path for PDO.mysql sock in /etc/php.ini. Now, edit your /etc/php.ini :

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
#pdo_mysql.default_socket=/var/mysql/mysql.sock
pdo_mysql.default_socket=/tmp/mysql.sock


Then restart your Apache now.

To assure if you give the right path, read your MySQL default socket in /etc/my.cnf. Now, you can install Drupal 7 in your Mac OS X Snow Leopard. Voilaa!!

In case, you still found error, then install PDO_MYSQL from http://pecl.php.net/package/PDO_MYSQL

wget -c http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
gunzip PDO_MYSQL-1.0.2.tgz
tar -xvvf PDO_MYSQL-1.0.2.tar
cd PDO_MYSQL-1.0.2
phpize
LDFLAGS='-arch x86_64' ./configure --with-pdo-mysql=shared,/usr/local/mysql
make
sudo make install

After install, you will receive where path this PDO module installed, in my Mac, like this :

Macbook-Pro:PDO_MYSQL-1.0.2 yodi$ sudo make install
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/


Then edit your /etc/php.ini and add this line inside :

extension_dir="/usr/lib/php/extensions/no-debug-non-zts-20090626/"
extension=pdo_mysql.so



Then restart your Apache!

From Ben :

If you are trying to compile with the above directions and you have a 32-bit version of MySQL you might receive the error below as I did.
configure: error: mysql_query missing!?

To resolve the issue I simply compiled by changing x86_64 to i386.

Tags:



You should follow me here

Comments

If you are trying to compile with the above directions and you have a 32-bit version of MySQL you might receive the error below as I did.

configure: error: mysql_query missing!?

To resolve the issue I simply compiled by changing x86_64 to i386.

Hope this helps someone.

Thanks ben, my article already updated with your comments :)

Thanks this site for everything. I 've just make my ex girlfriend to return with me. Thanks , thanks , thanks

This really helps, i fixed my relationship using this tutorial too!! Thank You!

when i add the line "extension=pdo_mysql.so" into the php.ini,
the browser will display that it cannot connet to the localhost.
do u know y?

excuse me....
when i add the line "extension=pdo_mysql.so" into the php.ini,
the browser displays that it cannot connect to the localhost.
do u know y?

Hi haik,

Can you provide more information ?
Did you check your MySQL service already running?

Make sure all service works properly.
Use phpinfo() to see pdo_mysql.so already loaded.

I simply created a mysql directory under /var then created a symbolic link in that directory named mysql.sock that pointed to /tmp/mysql.sock. Problem solved. Had to use sudo:
sudo mkdir /var/mysql
cd /var/mysql
sudo ln -s /tmp/mysql.sock mysql.sock

Add new comment