Export and import a MySQL database
At the end you will have an SQL dump of the source database and that dump loaded into an empty database on the target server, with row counts checked.
What you need before step 1
Applies to: MySQL 8.0 and 8.4 (commands also used with MariaDB), command line or phpMyAdmin, as documented in the MySQL Reference Manual and phpMyAdmin documentation
Admin roles you need
- Source database account with SELECT on the tables, SHOW VIEW for views, TRIGGER for triggers, LOCK TABLES (unless you use --single-transaction) and PROCESS (unless you use --no-tablespaces), as listed in the mysqldump documentation
- Target database account that can create the database (or an empty database already created by your host) and create and insert into tables
- phpMyAdmin route: login to phpMyAdmin through your hosting control panel
Licences
None needed.
Reference documentation
https://dev.mysql.com/doc/refman/8.4/en/mysqldump.htmlReadhttps://docs.phpmyadmin.net/en/latest/import_export.htmlReadAlso have ready
- Database host name, port, database name, user and password for source and target (for WordPress, from wp-config.php)
- Enough disk space for the dump file on the machine running mysqldump
- A maintenance window or read-only period if the data must not change during the copy
8 steps
- 1
Export with mysqldump
Where: SSH session or terminal on a machine that can reach the source database (Linux/macOS shell or Windows Command Prompt)Dump one database.
--databasesadds CREATE DATABASE and USE statements so the dump reloads into a database of the same name; leave it out if you want to load into a database with a different name.--single-transactionissues a BEGIN before dumping; with it, the LOCK TABLES privilege is not required.--routinesand--eventsinclude stored procedures, functions and events. Enter the password when prompted.mysqldump -h db.contoso.com -u contoso_admin -p --single-transaction --routines --events --databases contoso_db > contoso_db.sqlYou should see: The command returns to the prompt with no errors and contoso_db.sql has a non-zero size. - 2
Windows PowerShell: use --result-file
Where: Windows PowerShellMySQL warns that a dump made in PowerShell with
>redirection is UTF-16 encoded and cannot be loaded correctly. In PowerShell write the file with--result-fileinstead.mysqldump -h db.contoso.com -u contoso_admin -p --single-transaction --routines --events --databases contoso_db --result-file=contoso_db.sqlYou should see: contoso_db.sql is created and opens as readable text. - 3
Or export with phpMyAdmin
Where: Hosting control panel > phpMyAdmin > select the database in the left pane > Export tabChoose Custom, make sure the format is SQL, tick Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement, choose gzipped compression for a smaller file, and select Go. For big tables, the Maximal length of created query option splits large extended INSERTs, which phpMyAdmin's documentation says can help avoid max_allowed_packet errors on import.
You should see: The browser downloads contoso_db.sql or contoso_db.sql.gz. - 4
Copy the dump to the target server
Where: Your PC or the source serverCopy the file with scp, SFTP or your host's file manager. Compress it first if it is large.
gzip contoso_db.sql scp contoso_db.sql.gz admin@newserver.contoso.com:/home/admin/You should see: The file is on the target server with the same size. - 5
Create the target database if the dump has no CREATE DATABASE
Where: SSH session on the target serverSkip this if you used
--databases. Otherwise create an empty database first (many hosts make you create it in the control panel instead). Use the same character set as the source database; check it on the source withSHOW CREATE DATABASE contoso_db;.mysql -u contoso_admin -p -e "CREATE DATABASE IF NOT EXISTS contoso_db CHARACTER SET utf8mb4;"You should see: No output. SHOW DATABASES; now lists contoso_db. - 6
Import with the mysql client
Where: SSH session on the target server (Linux/macOS shell or Windows Command Prompt)If the dump contains CREATE DATABASE and USE, load it with no database name. If not, name the target database. In Windows PowerShell the
<character is reserved, so wrap the command incmd.exe /c. You can also load it from inside the mysql client withsource.gunzip contoso_db.sql.gz mysql -u contoso_admin -p < contoso_db.sql mysql -u contoso_admin -p contoso_db < contoso_db.sql cmd.exe /c "mysql -u contoso_admin -p contoso_db < contoso_db.sql"You should see: The command returns to the prompt with no ERROR lines. - 7
Or import with phpMyAdmin
Where: Target host control panel > phpMyAdmin > select the target database > Import tabChoose the .sql or .sql.gz file and select Import (or Go). If the file is too big to upload, phpMyAdmin's FAQ 1.16 lists the options: raise
upload_max_filesize,post_max_size(which must be larger),memory_limitandmax_execution_timein php.ini (your host can do this), upload the file to the server and use$cfg['UploadDir'], or import over SSH with the mysql client.You should see: phpMyAdmin reports that the import finished, and the tables appear in the left pane under the database. - 8
Compare the source and target
Where: mysql client on both servers (or phpMyAdmin Structure tab)Compare the table list and row counts for key tables on the source and the target.
mysql -u contoso_admin -p -e "SHOW TABLES;" contoso_db mysql -u contoso_admin -p -e "SELECT COUNT(*) FROM orders;" contoso_dbYou should see: The same tables exist and the row counts match.
Expert tips
--single-transaction takes a consistent snapshot of InnoDB tables without locking them, so the site can stay up. It does not protect MyISAM tables, and no one should run ALTER, CREATE, DROP, RENAME or TRUNCATE TABLE while it runs. Without it, mysqldump needs the LOCK TABLES privilege.
MySQL says mysqldump is not a fast or scalable solution for large amounts of data and suggests the MySQL Shell dump utilities, which dump in parallel with compression and progress display. For very large systems, a physical backup restores much faster than SQL.
mysqldump needs the PROCESS privilege unless you add --no-tablespaces. On shared hosting and managed databases you rarely get PROCESS, and most application databases do not use tablespace statements, so add the flag.
If the source has GTIDs enabled, the dump can include SET @@GLOBAL.GTID_PURGED, which some managed or replica targets refuse. Add --set-gtid-purged=OFF when you are moving data, not building a replica.
Add --hex-blob if tables hold binary columns (images, files, encrypted values). It writes them in hexadecimal, so character set conversion on the way cannot corrupt them.
How to confirm it worked
The table list on the target matches the source.
Row counts for your largest and most important tables match.
The application (for example WordPress) connects to the new database and shows recent records, with accented characters and emoji displayed correctly.
How to reverse it
Exporting does not change the source. To undo an import, drop the target database (DROP DATABASE contoso_db;) or restore it from a backup taken before the import. Importing a dump made with DROP TABLE statements replaces existing tables of the same name, so take a backup of the target first if it already has data.
Errors you might see
mysqldump: Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation'Cause: mysqldump needs PROCESS unless --no-tablespaces is used.
Fix: Add --no-tablespaces, or ask the DBA to grant PROCESS.
Garbled characters or a load failure for a dump made in PowerShellCause: Output redirection in PowerShell creates a UTF-16 file, which MySQL cannot use as a connection character set.
Fix: Recreate the dump with --result-file=contoso_db.sql.
The '<' operator is reserved for future use.Cause: PowerShell reserves the less-than character, so input redirection does not work.
Fix: Wrap the import in cmd.exe /c as shown in the import step, or use source inside the mysql client.
ERROR 1046 (3D000): No database selectedCause: The dump was made without --databases, so it has no USE statement, and no database was named on import.
Fix: Create the database and run mysql with the database name, or USE contoso_db; before source.
phpMyAdmin import fails on a big file (memory, HTTP or timeout)Cause: PHP upload, memory or time limits.
Fix: Follow phpMyAdmin FAQ 1.16: raise the PHP limits, use UploadDir, or import over SSH with mysql.
Questions
Is mysqldump suitable for very large databases?
MySQL says it is not intended as a fast or scalable solution for substantial amounts of data, and restores can be slow. Consider the MySQL Shell dump utilities or a physical backup.
What is the difference between dumping with and without --databases?
With --databases the dump includes CREATE DATABASE and USE statements. Without it you must name a target database when loading, which lets you load into a different name.
Should I compress the dump?
Yes for transfer. mysqldump output can be piped to gzip, and phpMyAdmin can export and import gzipped files.
How do I keep accented characters and emoji intact?
Avoid PowerShell redirection (use --result-file) and create the target database with the same character set as the source (check it with SHOW CREATE DATABASE on the source).
Official sources
Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.