What is the best and fastest way to move mysql when changing servers?
Currently I do it through phpmyadmin, I backup the db in the old server, open a new user in the new server, create a new database and upload/restore the backup.
(I use something like this to speed up the database restore with mysql terminal.)
mysql -u username -p database < /var/www/html/mysql_dump/nomedb.sql
A long and tedious operation... can it be done in a better and faster way to copy database and mysql users to the new server?
I have ssh access and server root, ubuntu 20.04 server, apache, php8.1
----------update---------
Just for completeness, I regularly use this script to make mysql backups, and I download everything with rsync to a local disk, so backing up databases is not a problem. The tedious part is restoring them one by one... https://www.alebalweb-blog.com/66-backup-automatico-mysql-su-server-ubuntu.html (Sorry, the description is in italian, but it's almost all code...)
“Best” is rather subjective, leading to opinions, but this is generally the method I follow when setting to a new MySQL database:
On the new server …
On the source server …
Export the databases one by one:
Note: You do not need to use the command line for this if you prefer phpMyAdmin or another tool.
-n
⇢ Suppress the CREATE DATABASE ... IF EXISTS statement--routines
⇢ Dump stored routines (functions and procedures)--triggers
⇢ Dump triggers for each dumped tablePackage and compress the database dumps for easier transport:
Copy/Send the compressed file to the new server
On the new server …
There are other ways to do this, but I follow this process as it allows me to avoid the problems of overwriting differing versions of the
mysql
system table (if the new server is not the exact same version) while also ensuring all data, accounts, permissions, and functions/procedures/triggers are in place.