In this guide, we will see how to connect to a database MySQL created on a Plesk server.
MySQL database connection parameters
First of all, you should know that you need four parameters to connect to the MySQL database;
- The host name (or server) that hosts the database.
- The name of the database.
- The user name of the database.
- The password of the database user.
If you have not yet created your MySQL database in Plesk, please follow this help link.
For shared servers, it is not possible to connect to the MySQL database from a server external. The connection can only be established on the shared hosting server.
Basically, only the scripts of your website hosted on the same database server can access the database, insert, delete and modify data.
Connecting to a MySQL database from WordPress
The MySQL database connection chain is very simple. Here is an example of the configuration file wp-config.php from WordPress which allows access to the database:
/** The name of the database for WordPress */
define('DB_NAME', 'ma-base');
/** MySQL database username */
define('DB_USER', 'my-user');
/** MySQL database password */
define('DB_PASSWORD', 'uNrd41!7');
/** MySQL hostname */
define('DB_HOST', 'localhost:3306′);
Any other script must have the same connection parameters for the connection to the database to be established properly.