Remote Database Setup and Performance Optimization with MySQL on Ubuntu
📘 What Will You Learn in This Guide?
As your application grows, the single server architecture reaches its performance limit.
In this guide, you will learn how to ensure load distribution, security and scalability by separating MySQL and the web server.
🧠 Technical Summary
This guide explains how to install remote MySQL database on Ubuntu.
The goal is to improve performance in applications that use MySQL, such as WordPress.
Steps: MySQL configuration, SSL, user privileges, WordPress integration.
Preliminary Preparations
Before starting the installation, the following should be ready:
- 2 Ubuntu servers
- Database Server (MySQL)
- Web Server (Nginx + PHP)
- sudo authorized user on both servers
- UFW firewall active
- (Recommended) Same data center and private network
1. Opening MySQL to Remote Connections
(Database Server)
MySQL only accepts localhost connections by default.
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
- This command opens the MySQL configuration file.
[mysqld]
bind-address = veritabani_sunucu_ipsi
require_secure_transport = on
- This setting opens MySQL to external connections and enforces SSL.
sudo mysql_ssl_rsa_setup --uid=mysql
- This command generates SSL certificates for MySQL.
sudo systemctl restart mysql
- MySQL is restarted to apply the changes.
sudo ufw allow mysql
Port 3306 is opened in the firewall.
2. Database and User Creation
sudo mysql
- Logs into the MySQL console.
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-Creates database for WordPress.
CREATE USER 'yerel_kullanici'@'localhost' IDENTIFIED BY 'guclu_sifre';
GRANT ALL PRIVILEGES ON wordpress.* TO 'yerel_kullanici'@'localhost';
Defines users for local administration.
CREATE USER 'uzak_kullanici'@'web_sunucusu_ipsi' IDENTIFIED BY 'guclu_sifre';
GRANT ALL PRIVILEGES ON wordpress.* TO 'uzak_kullanici'@'web_sunucusu_ipsi';
FLUSH PRIVILEGES;
EXIT;
This user can only connect from the web server.
3. Testing the Connection
(Web Server)
sudo apt update
sudo apt install mysql-client
- MySQL client is installed.
mysql -u uzak_kullanici -h veritabani_sunucu_ipsi -p
The connection to the remote database is tested.
```sql
status;
```sql
status;
```bash
sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip
```bash
sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip
```bash
sudo systemctl restart php8.1-fpm
```bash
sudo systemctl restart php8.1-fpm
```bash
sudo nano /etc/nginx/sites-available/your_site_address
```bash
sudo nano /etc/nginx/sites-available/site_adresiniz
```nginx
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
```nginx
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
```bash
sudo systemctl reload nginx
```bash
sudo systemctl reload nginx
```bash
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
```bash
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
```bash
sudo cp -a /tmp/wordpress/. /var/www/your_site_address
sudo chown -R www-data:www-data /var/www/your_site_address
```bash
sudo cp -a /tmp/wordpress/. /var/www/site_adresiniz
sudo chown -R www-data:www-data /var/www/site_adresiniz
```bash
cp wp-config-sample.php wp-config.php
nano wp-config.php
```bash
cp wp-config-sample.php wp-config.php
nano wp-config.php
```php
define('DB_NAME', 'wordpress');
define('DB_USER', 'remote_user');
define('DB_PASSWORD', 'strong_sifre');
define('DB_HOST', 'database_server_ipsi');
define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
```php
define('DB_NAME', 'wordpress');
define('DB_USER', 'uzak_kullanici');
define('DB_PASSWORD', 'guclu_sifre');
define('DB_HOST', 'veritabani_sunucu_ipsi');
define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
```arduino
https://site_adresinin.com/wp-admin
```arduino
https://site_adresiniz.com/wp-admin
Complete the setup wizard.
❓ Frequently Asked Questions (FAQ)
1. Why is it important to separate web and database? Resource sharing decreases, performance increases.
2. Is SSL mandatory? It is not mandatory, but it is essential for security.
3. Is this structure scalable? Yes, it is ideal for large projects.
4. What happens if I enter the wrong IP? MySQL rejects the connection.
🚀 Conclusion
Remote MySQL architecture provides performance and security. This structure is ideal for professional WordPress projects.
👉 You can set up this infrastructure in minutes on GenixNode.

