Remote MySQL access gives you the ability to connect to a MySQL database on this server from an another (remote) device or location over the internet.
Allowing remote MySQL access opens your database to connections from the entire internet, which may pose a security risk. Please consider the following:
If you're unsure about the security implications or need assistance, consult with your hosting administrator.
Remote MySQL access is disabled by default.
To enable remote access to your databases, click on the "Enable Remote MySQL Access" button in the "Databases > Remote MySQL" page.
Once enabled, you will be provided with an IP address and a port that you can utilize to establish a secure connection to the MySQL service from a remote server.
:::info
The displayed port is randomly generated and unique to your MySQL instance. Avoid using the standard port 3306
for remote access, as it will not function.
:::
To test remote MySQL access from another server, you can use the mysql
command-line client or a database management tool.
Ensure that you have the MySQL client installed on the server from which you want to access the MySQL database.
Use the following command to connect to the MySQL server from the remote server:
mysql -h <IP_ADDRESS> -P <PORT> -u <USERNAME> -p <DATABASE_NAME>
To establish a PHP-based connection from a remote server to a MySQL instance hosted on OpenPanel, here's an example code snippet:
<?php
// MySQL server details
$hostname = 'IP_ADDRESS_HERE';
$port = 'CUSTOM_PORT'; // Custom port from the OpenPanel interface
$username = 'YOUR_MYSQL_USERNAME';
$password = 'YOUR_MYSQL_PASSWORD';
$database = 'YOUR_MYSQL_DATABASE';
// Create a connection
$conn = new mysqli($hostname, $username, $password, $database, $port);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected to the MySQL server on $hostname:$port successfully.";
// Close the connection
$conn->close();
?>
To connect to a MySQL instance on OpenPanel from a remote WordPress installation, you need to edit the wp-config.php file and change the database connection information.
// ** MySQL settings - You can get this info from your web host **
/** The name of the database for WordPress */
define('DB_NAME', 'YOUR_MYSQL_DATABASE');
/** MySQL database username */
define('DB_USER', 'YOUR_MYSQL_USERNAME');
/** MySQL database password */
define('DB_PASSWORD', 'YOUR_MYSQL_PASSWORD');
/** MySQL hostname with custom port */
define('DB_HOST', 'IP_ADDRESS:PORT');
If you wish to disable access, simply click on the "Disable Remote MySQL Access" button, and it will immediately deactivate remote access in your MySQL configuration. Please be aware that this action will also necessitate a MySQL service restart to apply the new setting.