Moving a database from alternative MySQL (Docker) to the main server

Databases on alternative MySQL servers run in a Docker container. The main server is more stable and faster: if the site does not need a special MySQL version, move the database there.

The old database on the mysql-8.0 server (Docker)
The old database on the mysql-8.0 server (Docker)

1. Create a new database on the main server

  1. "Databases" → "Create a database".
  2. Database name; the owner is the same user as the site owner.
  3. "Database server" — MySQL (native), the main one.
  4. Database username and password. Write them down — you need them for the site config.
  5. Click "Create".
New database on the main server
New database on the main server

2. Export the old database dump

  1. Select the old database → "Dump" → "Export". The browser downloads a .sql file.
Exporting the old database dump
Exporting the old database dump

phpMyAdmin works too: the database → "Export" → "Quick" → SQL → "Go".

3. Import the dump into the new database

  1. Select the new database → "Dump" → "Import".
  2. "Upload type" — "Local computer file". Choose the downloaded file and click "Upload".
  3. Wait until it finishes. The bigger the file, the longer it takes.
Import into the new database
Import into the new database
Uploading the dump
Uploading the dump
The new database is filled
The new database is filled

A big dump is faster to load over SSH as root:

mysql -u shop_new -p shop_new < shop_old.sql

The opposite task — loading a dump into a container database: docker exec -i mysql-8.0 mysql -uroot -p shop_old < shop_old.sql (the container name is in the "Docker" section).

4. Change the connection in the site config

Open the site settings file and enter the new database details. The host is localhost without a port.

CMSWhere
WordPresswp-config.php: DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
OpenCartconfig.php and admin/config.php: DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE
Joomlaconfiguration.php: host, user, password, db
Laravel.env: DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD
define( 'DB_NAME', 'shop_new' );
define( 'DB_USER', 'shop_new' );
define( 'DB_PASSWORD', 'new database password' );
define( 'DB_HOST', 'localhost' );   // was 127.0.0.1:3310

5. Check and delete the old database

  1. Clear the site and browser cache. Go through the site and the admin area.
  2. No errors — delete the old database. If the alternative server has no more databases, you can delete it too: "Database servers".

A MySQL 8 dump contains the utf8mb4_0900_ai_ci collation. The main server (MariaDB 11) understands it. On old MariaDB versions replace it in the dump file with utf8mb4_unicode_ci.

How to install alternative versions: Database servers.

Questions and answers
The main server is faster and more stable than a container. If the site does not need a special MySQL version, keep the database on the main one.
A MySQL 8 dump contains utf8mb4_0900_ai_ci. If the main server does not know it, replace it with utf8mb4_unicode_ci in the dump file and import again.
Only after checking the site on the new database. Go through the site and the admin area first.