The database connection is the heart of a PrestaShop store's operation: it stores products, orders, customers, and all critical data. An interruption of this connection ("Access denied - Link to database cannot be established") blocks access to the site and prevents any sales. This article details the causes, diagnostic steps, and best practices to correct and prevent these errors.
Understanding the database connection error
The error "Access denied - Link to database cannot be established" means that PrestaShop is unable to establish a connection between your site and the MySQL/MariaDB server. The main causes are:
- Incorrect connection credentials (username, password, database name, host)
- Insufficient MySQL user rights
- Database server inaccessible or offline
- Server or hosting configuration issues
- PHP/MySQL version incompatibility or server overload
2. Diagnostic and Resolution Steps
Check the login information
The login settings can be found in the file/app/config/parameters.php (PrestaShop 1.7+) or/config/settings.inc.php (previous versions). Please verify that the following values correspond to those provided by your hosting provider:
-
database_host(orDB_SERVER) -
database_name(orDB_NAME) -
database_user(orDB_USER) -
database_password(orDB_PASSWD)
A simple typographical error in these fields can generate the error. In case of doubt, test the connection using an external tool (PHPMyAdmin, test PHP script).
Check the MySQL permissions and privileges.
The configured MySQL user must have sufficient rights (SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER) on the relevant database. Verify or assign these rights through your hosting provider's management interface (cPanel, Plesk) or an appropriate SQL command:
GRANT ALL PRIVILEGES ON nom_base.* TO 'utilisateur'@'localhost' IDENTIFIED BY 'motdepasse';
FLUSH PRIVILEGES;
Insufficient rights may prevent connection or data recording.
Ensure that the database server is online.
The MySQL/MariaDB server must be operational and accessible from your web hosting. Check:
- That there is no maintenance or incident on the hosting provider's side.
- That the host name (
localhost, IP, or URL) is correct. - That the port used is open (by default, most often, 3306).
Use PHPMyAdmin or a PHP script to test the connection. On certain shared hosting services, remote access to the database may be restricted.
Check the compatibility of versions and server configuration.
A PHP/MySQL version incompatibility may cause connection errors. To verify these compatibilities, please refer to the article Required Configuration for PrestaShop. Also check the server limits:
-
memory_limit(512 M recommended) -
max_execution_time(300 s or more) -
upload_max_filesize(64 M or more)
Adjust the configuration on cPanel, or in the filephp.ini or.htaccess if necessary.
Analyze the error logs.
Activate debug mode in PrestaShop (define('_PS_MODE_DEV_', true); inconfig/defines.inc.php) to display detailed error messages. Also, consult the log files:
-
/var/logs(PrestaShop 1.7+) - Web server logs (Apache/Nginx)
- Error logs in cPanel/Plesk
The messages can assist in identifying a SQL syntax error, a quota overflow, or a faulty module.
Special cases and common errors
Incorrect parameters inparameters.php orsettings.inc.php
An error in these files is the most common cause. Please check each field, especially after a migration, restoration, or update.
File permission issues
Permissions must be 644 for files, 755 for directories. Overly permissive rights (777) expose your site to hacking risks.
MySQL server overload or failure.
An overloaded server or an inappropriate configuration (insufficient resources, too short timeout, exceeded quotas) can cause "MySQL server has gone away" errors or connection losses. Monitor resource usage and request your hosting provider to increase the limits if necessary.
Hosting issues.
Some hosting providers impose specific restrictions (remote access, query limitations, PHP version). In case of doubt, contact the technical support of your hosting provider to verify the configuration and any restrictions in place.
4. Best Practices and Prevention
- Secure your access: never use the root user for PrestaShop, but rather a dedicated user with limited rights.
- Change the table prefix during installation to limit the risks of SQL injection.
- Regularly update PrestaShop and its modules to benefit from the latest security patches.
- Frequently back up the database and configuration files.
- Monitor security (SSL, firewall, antivirus scanning) and server availability.
Example of a connection testing procedure.
You can create a filetest_db.php at the root of your site to test the MySQL connection:
<?php
$mysqli = new mysqli('database_host', 'database_user', 'database_password', 'database_name');
if ($mysqli->connect_errno) {
echo "Échec de la connexion à MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
} else {
echo "Connexion réussie à la base de données !";
}
?>
Replace the parameters with those of your configuration. If the connection fails, the error message displayed will guide you to the precise cause.
|
⚠️ Always delete this type of files after use, as they represent a potential security vulnerability. |
6. When to contact your hosting provider or an expert?
If, after all these checks, the error persists, it is likely that the problem is related to the hosting provider's infrastructure (server outage, maintenance, network restrictions). Contact your hosting provider's technical support with detailed error messages and the list of tests already performed to expedite the resolution.
7. Summary of Key Points
- Verify and correct the identifiers in the configuration file.
- Ensure that the MySQL user has the necessary rights.
- Test the availability of the MySQL server.
- Check the compatibility of the versions and the server resources.
- Analyze the logs to refine the diagnosis.
- Apply best practices for security and maintenance.
By following these instructions, most "Access denied - Link to database cannot be established" errors on PrestaShop can be resolved quickly and sustainably, ensuring the availability of your online store and the security of your data.