Article ID: 114361, created on Jul 13, 2012, last review on Jun 16, 2016

  • Applies to:
  • Plesk 11.5 for Windows


Some domains are returning this error:

Database connection error (2): Could not connect to MySQL


The error means that the some domain's script is trying to connect to a MySQL database, but is failing to do so.


First, find the script and make sure it is using the correct database name and credentials when connecting. For illustration purposes, let us assume that the script is using these credentials:

Database: testdb
Host: localhost
Username: testuser
Password: test
  1. Log in to the server via SSH and try to connect to the same database manually using the above credentials:

    # mysql -h localhost -utestuser -ptest testdb
  2. If the connection fails, make sure that the needed database, user, and password indeed exist on the server. Even if they are shown in the Plesk web interface, check if they exist in MySQL directly.

    For example, it may be that the testuser is missing from the mysql.user table. In that case, add the user manually by running these commands in the shell:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin mysql
    mysql > GRANT USAGE ON *.* TO 'testuser'@'%' IDENTIFIED BY 'test';
    mysql > GRANT ALL PRIVILEGES ON `testdb`.* TO 'testuser'@'%';
    mysql > FLUSH PRIVILEGES;``

56797cefb1efc9130f7c48a7d1db0f0c a914db3fdc7a53ddcfd1b2db8f5a1b9c 85a92ca67f2200d36506862eaa6ed6b8 46a8e394d6fa13134808921036a34da8 bd7fc88cf1b01f097749ae6f87272128

Email subscription for changes to this article
Save as PDF