Cannot connect WordPress to MySQL database

Doing some local website work to learn WordPress theme development.

Tried to set up WordPress through the prompts, also tried it by manually entering information in the wp-config.php file, neither would work. Still cannot connect to the database, the setup-config.php page returns “Error establishing a database connection”. I’ve double, triple, and quadruple checked the login credentials (database name, username, password etc.), they are complete and correct. Deleted wp-config.php and tried again through the web page, same result.

Read More

MySQL is definitely running, the Mac System Preferences panel says so, and I can login and run SQL queries at the command line, although I have to do that as root. Should I be running MySQL as root?

This problem exists with WordPress and also with an instance of phpMyAdmin that I’ve also installed, so I don’t think it’s anything to do with the PHP code as such, it smells more like a permissions thing. For what it’s worth, I’ve edited my httpd.conf file to get WordPress on port 80 and phpMyAdmin on 8081. Apache is serving those sites up as it should and PHP is running, it’s just getting either site to connect to the database that’s the problem.

System information:

Mac OS X 10.9.5 (Mavericks)

PHP Version 5.4.30

MySQL version:
mysql Ver 14.12 Distrib 5.0.45, for apple-darwin9.2.0 (i686) using EditLine wrapper

Related posts

Leave a Reply

4 comments

  1. In my case it was as simple as changing the DB_HOST so it was using the correct host and port in wp-config.php:

    define('DB_HOST', '127.0.01:3306');
    
  2. I found the solution on this stackoverflow page.

    By default, Apache cannot send requests to a remote MySQL server. It should be enabled.

    On CentOS 6 the solution is the command:

    setsebool httpd_can_network_connect=1
    
  3. I experienced a similar issue and it turned out that the authentication type used by MYSQL was not supported.

    To verify this, add

    define('WP_DEBUG', true)
    

    in the wp-config.php and re-run the installation. You will see an entry indicating if that’s the case.

    If the issue is confirmed to the authentication method, try

    mysql> CREATE USER ‘username’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
    

    after logging in to mysql console.