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.sockThen 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.tgzgunzip PDO_MYSQL-1.0.2.tgztar -xvvf PDO_MYSQL-1.0.2.tarcd PDO_MYSQL-1.0.2phpizeLDFLAGS='-arch x86_64' ./configure --with-pdo-mysql=shared,/usr/local/mysqlmakesudo 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.
Comments
Ben (not verified)
Sun, 12/12/2010 - 13:40
Permalink
MySQL 32-bit works too
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.
admin
Mon, 12/13/2010 - 10:27
Permalink
Thanks Ben
Thanks ben, my article already updated with your comments :)
Avascalcurl (not verified)
Wed, 01/12/2011 - 08:00
Permalink
Seotons
Thanks this site for everything. I 've just make my ex girlfriend to return with me. Thanks , thanks , thanks
Jancis (not verified)
Wed, 10/19/2011 - 13:31
Permalink
This really helps, i fixed my
This really helps, i fixed my relationship using this tutorial too!! Thank You!
haik (not verified)
Mon, 10/17/2011 - 19:57
Permalink
when i add the line
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?
haik (not verified)
Mon, 10/17/2011 - 20:01
Permalink
excuse me....
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?
admin
Tue, 10/18/2011 - 00:46
Permalink
can you provide more information ?
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.
Bill (not verified)
Wed, 05/16/2012 - 10:19
Permalink
Alternate solution
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