This article is intending to help you in debugging MySQL connection issues.
Check if MySQL server is up - simply connect via ssh, and use the command:
ps aux | grep mysqland check if you have at least 2 results. Another way to check it will be by using
htop, and looking for the MySQL process, or just check the BunnyShell monitoring/services section. If your MySQL is down you can start it using
sudo service mysql restart.
Check if MySQL credentials are valid - connect to VM via ssh, get VM credentials from BunnyShell application and use it in MySQL CLI client:
mysql -user -p, replace the user with your user name, it can be used with no space between -u and user as in the above example. After hitting enter you will be prompted for your password. Type it and hit enter. It won't be displayed as you type it, for security reasons, so don't worry if you don't see any stars when you type it in. If you don't get any errors, but in return, you get MySQL shell
mysql>then your credentials are working.
Next, you will check if the database exists and your user has appropriate rights to connect to it. So after you are logged in, into MySQL as it is explained in the previews step, you use MySQL command
use database;, where you replace the word database with your database name.
If your issue is related to step 2 or 3 for fixing it, you should log in as MySQL root user, and use create user/give rights to your user to use/create the database.
There are some situations in which your tables are crushed so you will need to run
-databases -uroot -pand enter your root password in order to check and repair your databases and tables.
Enable WP_DEBUG in your wp-config.php - it will give you additional information about any errors.
Check your wp-config if your MySQL credentials, database name and host are correct.
Check your app configuration file and make sure that the credentials are correct, host and database.
If your MySQL server is running on the same Virtual Machine as your application, please make sure that your configuration file is using localhost as address/host for MySQL connect and not some IP address.
If your application uses an external MySQL server please check the firewall settings on that server and make sure that the port 3306 is opened for your application VM IP. You can also check this , by using telnet:
telenet mysql_ip 3306, where mysql_ip is your MySQL server IP address. You will get a connection error if there is some firewall or bad IP address/server is down.
If you import an application from some other servers, and you get MySQL errors, please make sure that you import your previous database also. Also check that all the content is in there.