Sunday, December 4, 2011

WordPress on OS X : Error establishing connection mysql

Recently I was trying to install/configure WordPress on OS X (Lion) with MySql 5.5. After reading the installation guide, I did not expect anything to go wrong, but as it goes without saying, theory is totally different from practical, I did face issue. After setting wp-config.php, when I hit the /wordpress/wp-admin/install.php, I got a nice page saying Error establishing a database connection. Obvious reason for this would be (as mentioned on the error page) would be the wrong user/password or wrong host or wrong database name. I checked all parameters and none were wrong and I was also able to connect to MySQL database which I created for WordPress with MySQL WorkBench and also from mysql command line.

To verify my settings, I just created and a test php page to test if I can connect to my newly create WordPress database. I was not able to connect and got some more details about no connection. I got following wraning

ErrorException [ Warning ]: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)
Obviously when I checked /var/mysql/mysql.sock, I could not find it. So next step was to find where is my missing mysql.sock and found it under /tmp. After googling a lot, I could not find any concrete solution to resolve this. Niether there is anything which I can change for MySQL configuration nor for the PHP configuration. So my last resort and the easy solution was creating a symbolic link. I just created a symbolic link on /var/mysql to point to /tmp (sudo ln -s /tmp /var/mysql) and hit the refresh on WordPress installation page and everything was just smooth. Happy blogging :-)

 Cheers !!!
- Jay

7 comments :

  1. "So my last resort and the easy solution was creating a symbolic link. I just created a symbolic link on /var/mysql to point to /tmp (sudo ln -s /tmp /var/mysql) and hit the refresh on WordPress installation page and everything was just smooth."

    Thanks for the post. I am a newbie and I don't have a clue as to how to create the symbolic link that you mention. Can you please elaborate on how to do this? Thanks.

    ReplyDelete
  2. Command to create symbolic link is ln and the one I used is mentioned in post - sudo ln -s /tmp /var/mysql

    ReplyDelete
  3. Please let me know if you're looking for a author for your weblog. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I'd absolutely love to write some material for your blog in exchange for a link
    back to mine. Please send me an e-mail if interested.
    Many thanks!
    Also see my webpage - SEO North Wales

    ReplyDelete
    Replies
    1. Thanks for your offer. I'll let you know if required.

      Delete
  4. Thanks for such nice post. I got the exactly same error. I think this is OS X based error.
    Your solution really saved my some hours. Thankyou again.

    ReplyDelete
  5. I run into the same problem dude, and I almost did as you said, but after reading your article ...I took a breathing and realized after read the page error again I thought to myself I could solve this just by editing the mysql config file named my.cnf you can find it on /usr/local/mysql/my.cnf so what I did was just uncomment this line:
    # socket = .....

    See the command line step by step for doing it:

    @:~$ cd /usr/local/mysql
    @:/usr/local/mysql$ sudo nano my.cnf
    Password:

    On this file editing uncomment the line below and set up the value as shown:
    # socket = .....
    socket = '/var/mysql/mysql.sock'

    save the file and restart de mysql server

    thats enough for this rock & roll

    Thanks

    ReplyDelete
    Replies
    1. Thanks Adriano for sharing this. Always good to know alternate solutions.

      Delete

 
Disclaimer : This is a personal blog and all content represent what I think and it does not advocate/support/advertise any other person/company. I do not earn money or intended to do so with this blog or any of the contents the blog hosts (except the google ads which you see). If I post something here that you find helpful, that's wonderful. Just in case, if I say something stupid, the stupidity is mine, and mine alone and I can not be held for anything if you fall for such stupidity :-). I cannot be held responsible for any kind of damage that may be caused by downloading or viewing the files or information provided herewith. Anybody and everybody can use/refer the contents of this blog at their own will and of course at own risk. There is no need for any kind of approval of the author. Although it would be great if feedback is left for any such usage to the author.