WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Error establishing a database connection on OS X 10.5 (22 posts)

  1. jonokane
    Member
    Posted 6 years ago #

    Hello All,
    First, I have done a ton of searching on this topic and I see that I'm not the only one having issues. Unfortunately, I have spent far too much time on this and I'm still scratching my head.

    I am using a fresh install of OS X Leopard, I have PHP 5.2.4 running, MySQL 5.0.51a MySQL Community Server running on top of OS X's pre-installed Apache. I can parse PHP, and I can connect to my local MySQL server via command line. I installed phpMyAdmin, and that's running smoothly locally as well (phpMyAdmin is able to connect read/write to/from MySQL).

    I keep getting the "Error establishing a database connection" page when I hit my local wp site. I have a fresh install of WordPress, with a double-triple-checked wp-config.php file. Configured as follows:

    define('DB_NAME', 'dbname');    // The name of the database
    define('DB_USER', 'root@localhost');     // Your MySQL username
    define('DB_PASSWORD', 'xxx'); // ...and password
    define('DB_HOST', 'localhost');    // 99% chance you won't need to change this valu
    e

    I tried changing the 'DB_HOST' designation to my machine's IP, this did not work as well.

    I have also re-assigned the mysql.default_socket php.ini:
    mysql.default_socket = /tmp/mysql.sock

    Additionally, the my.cnf file:

    [mysqld]
    socket=/var/mysql/mysql.soc

    I have tried restarting all services, re-installing all services (besides apache), and, well, I'm starting to lose hope! I have done wp installs a gazillion times, but never ever had an issue like this!!!! Someone please help! Any smart suggestions are greatly appreciated!

  2. jonokane
    Member
    Posted 6 years ago #

    Followup: After spending what seems like an absolutely ridiculous amount of time on this, I have figured out the embarrassingly simple issue.

    localhost != Localhost

    My Mac identifies itself as Localhost, NOT localhost! Learned something extremely obvious.... :)

    So the config should look like this:

    define('DB_NAME', 'dbname');    // The name of the database
    define('DB_USER', 'root');     // Your MySQL username
    define('DB_PASSWORD', 'xxx'); // ...and password
    define('DB_HOST', 'Localhost');    // 99% chance you won't need to change this value
  3. thesheep
    Member
    Posted 6 years ago #

    Thanks. I just got stuck on the same thing and your post saved me.

  4. breakthruhere
    Member
    Posted 6 years ago #

    Wow! Same problem here... I wasted hours on this. Id like to know where the problem lies... One small capitalisation of a letter in the code for the latest release? or a problem with 10.5?

    jonokane, how did you find out?

    Quote: "99% chance you won't need to change this value"

    More like: "100% chance you will do youre head in trying trying to figure out why your machine wont respond to the the host name "localhost!!!!""

  5. breakthruhere
    Member
    Posted 6 years ago #

    I did some further testing regarding this issue as follows...

    Im hoping that this isnt a problem with apache. Ive done a bit of checking into my config files and all seems to be normal. (This is starting to bore me why the hell it works with a capital L.

    It seems it must be a problem with the code as I can connect to the target database with the same user name.

    1. Make a clean install of the wordpress-2.3.3.tar that I downloaded from http://www.wordpress.org

    2. Copy the files to a new subdirectory to compare with my working install

    3. Go through all the default files checking for any caps mistakes

    Ive tried both solutions with a clean and modified db (sql dump) from a previous install that worked no prob with the host name "localhost" not "Localhost"

  6. alui
    Member
    Posted 6 years ago #

    you saved my day after wasting HOURS on this type-case problem! thanks so much!

  7. mrogers
    Member
    Posted 6 years ago #

    Thanks for posting this! The same problem was driving me insane too. I never would have thought to change the name to a capital 'L'.

    This is definitely a bug in WordPress 2.5, because every other web app I have running on this machine uses "localhost" and it connects to the MySQL server just fine.

  8. brianmhull
    Member
    Posted 6 years ago #

    Man I poured over this for hours before finding this post. A local install on 10.4 was so easy, but 10.5 has been a nightmare. Glad to have found a good resources for 10.5 here.

    Thanks.

  9. heyitsgarrett
    Member
    Posted 6 years ago #

    Good lord! Thanks for this post. That was the problem with mine too. I was so confused.

  10. BradBrand
    Member
    Posted 6 years ago #

    Great $DIETY in $AFTERLIFE

    You probably saved me a grand in monitor damage and a couple grand more in emergency room bills. I never woulda figured this one out.

    Many thanks.

    jonokane-karma += 10

  11. ckuettner
    Member
    Posted 6 years ago #

    Here too, I lost too many hours on it... Thanks for resolving this!!!

    but I use Mac OS X 10.4, so this can't be a Leopard-only problem.

    I tried several WP versions so this is also not WP-version specific.

    And, yes, all the other web-apps successfully connected to MySQL.

  12. Anonymous
    Unregistered
    Posted 6 years ago #

    Silly. Thanks for the post. Hope it gets fixed soon.

  13. searchen
    Member
    Posted 6 years ago #

    Am sitting with the same issue, but it is not saved by the capitalization of 'localhost.

    Yesterday, I was unable to connect to the online-server (I somehow hot into a loop, and instead of displaying the front end, the link redirected to index.html).

    I actually have a site running successfully on a subdomain, and have other blogs all going fine on the same server. All with same version 2.5.1 and similar setup. This is voodoo.

    I have tried the same as suggested above, with new database, clean install, and still no luck.

    I am using WP 2.5.1, and am mega frustrated. The backend seemed to work OK with the old database, but wasn't fixing permalinks properly.

    Yikes...

  14. Lloyd Budd

    Posted 6 years ago #

    This isn't a WordPress issue, but a Mac issue. The correct solution is to set mysql.default_socket = /tmp/mysql.sock in /etc/php.ini.

    Details at http://foolswisdom.com/mac-wordpress-error-establishing-a-database-connection/

  15. damassipappas
    Member
    Posted 6 years ago #

    MY GOD!!!

    This needs to be stuck to the top!!! I was about to throw my computer out the window!!

  16. ProblemCocuk
    Member
    Posted 6 years ago #

    Hello my site ( http://www.problemcocuk.com ) have this problem. How can I optimize to mysql?

  17. wesg
    Member
    Posted 6 years ago #

    Oh man, that's so easy, and yet it would have taken me days to figure that out.

    Thanks!

  18. mutfak
    Member
    Posted 5 years ago #

    this is good article l have a need document about this article.

  19. paul
    Member
    Posted 5 years ago #

    Might be a good thing to add to the comments in wp-config-sample.php, no? Not sure if it's a bug or a feature but it would save people some time if they knew how to avoid getting stuck in it.

  20. kountz
    Member
    Posted 5 years ago #

    Thanks jonokane!!!

    I've just installed MySQL and wordpress using Xampp and had a similar problem with it. Changing the name of localhost to Localhost fixed it. Using Xampp works great - seconds to set up and if you correct the config.inc.php wp-config.php as above it should just take you about 5 mins to get a working local wordpress. :)

  21. tibra
    Member
    Posted 5 years ago #

    Thanks so much jonokane. I've spend 2 1/2 hours on this...damn stupid.
    Cheers

  22. Funkyjim
    Member
    Posted 5 years ago #

    Thanks for publishing your fix. This has saved me a great deal of (more) time. Props to you.

Topic Closed

This topic has been closed to new replies.

About this Topic