WordPress.org

Ready to get started?Download WordPress

Forums

Mac OS X Tiger database connection problems (and solution) (12 posts)

  1. ebow
    Member
    Posted 8 years ago #

    All,

    I've experienced some horribly frustrating problems the last week or so with installation since deciding I wanted to move to WordPress.

    I'm running Mac OS X 10.4.4 and have been wanting to try out WordPress locally (localhost) first. I downloaded and installed MySQL then WordPress, but WordPress steadfastly refused to connect to a database I'd set up for it, always returning: "Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at localhost. This could mean your host's database server is down."

    I've just spent quite some time in the #Wordpress IRC channel, where ringmaster ran me through the process of tapping setup-config.php to create a new wp-config.php, just in casse my settings were off. No luck; same error.

    PotterSys gave me some php code to check that my PHP was talking to my MySQL properly. That code, which just tested a database connection, returned:

    Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /path/to/test/script.php on line 2
    Uhm, MySQL is not working

    ringmaster said this showed that there was something wrong on my system in PHP talking to MySQL and, if not solved, just about nothing requiring MySQL would work.

    So I googled that error in a Mac OS X context. Turns out Mac Drupal users were experiencing the same unfathomable problem at the Drupal messageboard - it's all about the MySQL socket. One user said...

    The version of PHP that Apple included with Mac OS X 10.4.4 has mysql.default_socket set to "/var/mysql/mysql.sock", before it was "/tmp/mysql.sock". They change it for some security reasons I believe.

    The binary version of MySQL from mysql.com use "/tmp/mysql.sock" so one has to change.

    I choose to make PHP look for "/tmp/mysql.sock" by setting this in /etc/php.ini.

    The necessary variable setting used by the guy is included in that post.

    So I sought out my php.ini. Alas, I only had a php.ini.default. No problem. A person in the #php chatroom said you can just edit the setting and rename the file to take away the .default extension.

    After doing so, the error is missing from the test script, setup-config.php works, the rest of WordPress looks like it now wants to works and I hope to be a happier person (except when I look at .htaccess and directory name formats).

    Anyway, I really wanted to throw this out to the community because it was a hell of a job getting it fixed, it's totally not something you would think of, especially if, like me, you just wanted to download WordPress and go. Apparently, it's all because Apple changed the location of the MySQL socket in OS X 10.4.4.

    So, thanks to those who helped me and I hope you can benefit from this.

  2. ebow
    Member
    Posted 8 years ago #

    follow-up from #wordpress...

    Mrdini: ebow, ummm
    [23:00] Mrdini: ideally you SHOULDN'T edit php.ini.default
    [23:00] Mrdini: you're supposed to copy it to php.ini & edit the copy
    [23:00] ebow: err... ok
    [23:01] ebow: Mrdini: should i leave php.ini and php.ini.default coexist then?
    [23:01] ebow: someone in #php told me i could just edit the file and remove the .default extension
    [23:01] Mrdini: there's a reason why it's called php.ini.DEFAULT so you have a file to refer to, in case you kill your PHP install
    [23:02] Mrdini: think of php.ini.default as your backup, basically
    [23:03] ebow: Mrdini: ok, i did make a copy of it actually, so if i move that back to its original location, can php.ini and php.ini.default coexist at the same place? perhaps php.ini could contain only the setting different from the default? should the folder contain only one of them and i keep the default in a different location?
    [23:03] ebow: (i don't have a php-recommended.ini)
    [23:03] Mrdini: ebow, PHP doesn't look at php.ini.default at all - it only reads php.ini..... so basically, yes
    [23:03] [R] joined the chat room.
    [23:03] Mrdini: they can co-exist
    [23:04] ebow: ok, great ,thanks for your help
    [23:04] Mrdini: np

  3. gurami
    Member
    Posted 8 years ago #

    I ran into this problem as well, and there's another workaround:

    In your wp-config.php file:

    define('DB_HOST', 'localhost:/tmp/mysql.sock'); // 99% chance you won't need to change this value

    Instead of just localhost. For those of you savvy php coders:

    in wp-db.php, they pretty much just suck those values and pass them to mysql_connect(), so you can use a number of connection strings there for your db. These include

    [localhost]:/path/to/socket
    and
    ip_address:port

    Refer to the PHP documentation for more info.

  4. tanabb
    Member
    Posted 8 years ago #

    Thanks a lot!!!
    I had the same problem but didn't realize what was happening!

  5. crimemon
    Member
    Posted 8 years ago #

    I just bumped up to 10.4.6 and have been experiencing similar problems.

    I previously followed Gurami's advice (at http://wordpress.org/support/topic/60343?replies=4#post-333847) when I bumped up to 10.4.4:

    "In your wp-config.php file:

    define('DB_HOST', 'localhost:/tmp/mysql.sock'); // 99% chance you won't need to change this value

    Instead of just localhost.

    Now that I've upgraded it this correction no longer works--I get the dreaded connection error. Suggestions?

  6. FurrTrap
    Member
    Posted 8 years ago #

    I've wasted a month, off and on, since I received OSX 10.4.3 on April 25th, trying to get WP/MySQL working up to 10.4.6. Only when I rolled back from 10.4.6 to 10.3.9 on a dev partition did it work.

    I've opted for copying php.ini.default > php.ini and defining the default MySQL socket to /tmp/mysql.sock

    WP: 2.0.2
    OSX: 10.4.6
    MySQL: 4.1.19-standard
    PHP: 4.4.1

    "mysqladmin version" displays the unix socket and phpinfo() shows how the mysql socket is configured, so I should have spotted it! (Interesting to note that quite a few socket issues on the MySQL website.)

    Everything works fine now, thanks guys!

  7. johnsel
    Member
    Posted 8 years ago #

    Thanks for the great tip FurrTrap. It would've taken me a while to realise that too.

    If you don't want to edit php.ini.default, another option is to do the following in the terminal:

    $ sudo mkdir /var/mysql
    $ sudo ln -s /tmp/mysql.sock /var/mysql/

    I gotta admit I think it's a bit odd that the folks at MySQL don't build the OSX version with the right socket. I figure everyone must have this problem.

  8. FurrTrap
    Member
    Posted 8 years ago #

    I'll switch my install around the other way, to test the symlink. Not "played" with sym/hardlinks before, so it's worth knowing for other software that can only be fixed up this way.

    Now I've discovered that my local PHP 4.4.1 isn't compiled with GD (whatever that is!) as against PHP 4.4.1 on my webserver (which is)... (the SK2 Captcha plugin barfs on my local box).

    Thanks!

  9. thepolishtwin
    Member
    Posted 8 years ago #

    I'm having this problem on 10.3 (hence the part where it's not my main computer, its my web server ;) ), and I've tried the suggestions above. Anyone know why it's happening?

  10. crimemon
    Member
    Posted 8 years ago #

    I think I figured out part of my problem. I'm behind a firewall with four computers on the network. Whichever computer boots up first gets assigned one of the 7 IP numbers we have, so if I don't boot up the computer that stores the server _first_ I run into connection problems. I opened a free account with http://www.dyndns.com for a dynamically assigned IP # situation, which adjusts for this problem. It works, and it's cool.

  11. richschmidt
    Member
    Posted 8 years ago #

    I tried the symlink suggestion given by johnsel, and it worked for me on OS X 10.4.7...

  12. fluideye
    Member
    Posted 8 years ago #

    I tried the symlink suggestion given by johnsel, and it worked for me on OS X 10.4.7...

    me too! thanks alot johnsel, i was definitely stumped here because i'm running ror/lightTPD/MySQL successfully but could not get apache/php/mysql until now.

Topic Closed

This topic has been closed to new replies.

About this Topic