Support Online
Skip to main content

Moving MySQL Database to a New Server (Ubuntu)

What will you learn in this guide?

In this guide, you will learn separating application and MySQL database running on the same server.
The goal is to improve performance and make the infrastructure scalable.

🧠 Technical Summary

Main Technical Topic:
Migration of MySQL database between Ubuntu servers.

Solved Problem:
Insufficient resources due to increased traffic in LAMP architecture.

Steps Followed:

  • New MySQL server installation
  • Remote connection configuration
  • Backing up existing data
  • Data transfer to new server
  • Directing the application to the new database

1️⃣ Install New Database Server

Connect to your new server and install MySQL:

sudo apt-get update
sudo apt-get install mysql-server
sudo mysql_install_db
sudo mysql_secure_installation
  • These commands install MySQL and complete basic security settings.

2️⃣ Open MySQL to Remote Connections

  1. By default MySQL only listens on localhost.
  • Open the configuration file:

sudo vi /etc/mysql/my.cnf
  • This file contains MySQL network settings.

  • Find and replace the following line:

bind-address = YENI_SUNUCU_OZEL_IP
  • This setting allows MySQL to accept connections over private IP.

Restart the service:


sudo service mysql restart

3️⃣ Export Old Database Safely

  • Lock the database for data consistency:

FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;
  • This process prevents data exchange during migration.

  • Back up the database:

mysqldump --lock-all-tables -u root -p --all-databases > dump.sql
  • This command collects all databases in one file.

Transfer the backup to the new server:


scp dump.sql kullanici@YENI_DB_OZEL_IP:/tmp

4️⃣ Transfer Data to New Server

  • Import the backup on the new database server:

mysql -u root -p < /tmp/dump.sql
  • This step loads all existing data into the new MySQL server.

5️⃣ Create MySQL User for Application Server

  • MySQL users work with the logic of user + connecting IP.

Create the new user:


CREATE USER 'wp_kullanicisi'@'UYGULAMA_SUNUCU_OZEL_IP' IDENTIFIED BY 'guclu_sifre';

  • Define authorizations:

GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_kullanicisi'@'UYGULAMA_SUNUCU_OZEL_IP';
FLUSH PRIVILEGES;
  • This process allows the application to connect to the new server.

6️⃣ Update Application Configuration

  • If you are using WordPress, open the configuration file:

sudo vi /var/www/html/wp-config.php
  • Update database address:

define('DB_HOST', 'YENI_SUNUCU_OZEL_IP');
  • This setting redirects the application to the new MySQL server.

❓ Frequently Asked Questions (FAQ)

  1. Will the site go down during migration? No. The site goes into read-only mode.

  2. Why do we use private IP? Provides faster and more secure connection.

  3. Should I delete the old MySQL service? Stop it first. Remove after tests.


🚀 Result

By separating the database, you have made your infrastructure scalable. This structure creates a solid foundation for high traffic, replication and load balancing. You can safely grow your professional projects on the GenixNode infrastructure.