Error establishing a database connection when setup wordpress

Hi everyone,

i have create new website to my linode, i try setup my website but i can't pass step 2.Its show error
"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."

but all information is correct. i try log into mysql using SSH by information that i use to enter on setup website, it login successfully. I also try enter in wp-config.php but can't connect.
Anyone can help me solve this error?

3 Replies

@handymovik I'd be happy to help point you in the right direction! I can't be sure which instructions you followed when you set this up, but I will go through some of the instructions we have in our Guide - Install WordPress on Ubuntu 18.04.

Hostname Setup

You mention that you can't get past step number two. To be certain everything is set up from the beginning of these instructions, you'll want to check that your host name is set to match your domain.

Checking MySQL

  • You will also want to make sure the database service is running. You can check this using the below command to check and see if this service is listening and accepting connections. You will want to check for any mention of mysql.
sudo netstat -plunt

and then the below command, if mysql is not mentioned in that output:

sudo systemctl start mysql
  • It may also be helpful to review the information in your MySQL error logs.
sudo cat /var/log/mysql/error.log 
  • From there, you can check your database permission by logging into the MySQL as the root user. Keep in mind that this user will differ from the root user of your Linode. This is where you will create a WordPress user that will have permissions to access this specific database.

Troubleshooting wp-config.php Access

You mention that you can't connect to your wp-config.php file. If I'm understanding you correctly, this may be a permissions issue. If this is not the case, please, feel free explain what you mean when you say that you can't enter the file.

  • The wp-config.php file is created when WordPress is installed. If you are unable to access this file, the permissions for the website directory may need to be changed to set the web server's user as the owner.

For example:

sudo chown -R www-data:www-data /var/www/html/example.com/
  • After you've gained access to your wp-config.php file, you will want to review the database connection information which is located towards the beginning of the database information.

For example:

/** The name of the database for WordPress */
define('DB_NAME', 'database_name');

/** MySQL database username */
define('DB_USER', 'database_username');

/** MySQL database password */
define('DB_PASSWORD', 'database_password');

I hope this information helpful is helpful. Feel free to check out the below official WordPress resources for more information.


Additional Resources

Did you set up a root user for MySQL? The WP setup doesn't do this for you and depends on it being done ahead of time. Unless you choose specifically, the ssh login information is not the same for MySQL (or the default).

Do you have port 3306 blocked in your firewall?

-- sw

hi @rdaniels
i set up it like your guide Install WordPress on Ubuntu 18.04 but it not working. it still has error

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct