The Command
mysql appdb < dump.sqlThe database appdb must already exist. The same command works with MariaDB, where the client is also called mariadb. Credentials come from ~/.my.cnf, from the system root account through sudo on Ubuntu and Debian, or from a prompt: mysql -u app_ asks for the password instead of taking it on the command line.
Before You Import: Back Up the Target
Warning first: a dump made by mysqldump normally contains a DROP TABLE IF EXISTS statement before each table. Importing it into a database that already has tables with the same names replaces them, and their current data is gone. Look at the file and dump the target before you import over it:
grep -c 'DROP TABLE' dump.sql
grep -n -m 5 -E '^(CREATE DATABASE|USE )' dump.sql
sudo mysqldump --single-transaction appdb > appdb-before-import.sqlIf the second command finds CREATE DATABASE or USE lines, the dump was made with --databases or --all-databases and writes into the original database names, whatever name you give on the command line.
Step 1: Create the Database
sudo mysql -e "CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
sudo mysql -e "GRANT ALL PRIVILEGES ON appdb.* TO 'app_user'@'localhost'"The account 'app_ must exist already; see how to list MySQL users.
Step 2: Import
sudo mysql appdb < dump.sqlNo output means success. A compressed dump is unpacked on the fly:
gunzip < dump.sql.gz | sudo mysql appdb
zstd -dc dump.sql.zst | sudo mysql appdbShow Progress on Large Files
The pv tool shows how much of the file has been read (install the pv package; on AlmaLinux and Rocky Linux it comes from EPEL):
pv dump.sql | sudo mysql appdb
pv dump.sql.gz | gunzip | sudo mysql appdbRun long imports inside tmux, so a dropped SSH connection does not stop them; see the tmux cheat sheet.
Import from Inside the Client
USE appdb;
SOURCE /home/user/dump.sql;The path is on the machine where the client runs. This form prints a line per statement, which helps you see where an error occurs.
Character Set
If accented letters or other non-ASCII text look garbled after the import, set the connection character set to match the dump:
sudo mysql --default-character-set=utf8mb4 appdb < dump.sqlDumps made by mysqldump usually set this themselves near the top of the file.
Common Errors
- ERROR 1049, Unknown database: create the database first.
- ERROR 1044 or 1045, Access denied: the account lacks rights on that database or the password is wrong.
- ERROR 1227 about DEFINER: views or triggers name an account that does not exist here. Import as an administrative account, or create that account.
- Unknown collation: a dump from MySQL 8 or later that uses
utf8mb4_does not import into MariaDB before 11.4.5, which added it as an alias. On older MariaDB, replace it with0900_ ai_ ci utf8mb4_in a copy of the file.unicode_ ci - Packet too large or server has gone away: raise
max_in the server's configuration (or withallowed_ packet SET GLOBAL, which applies to new connections) and pass--max_to the client. The limit is 1G on both sides.allowed_ packet=512M
Check the Result
sudo mysql -e "SHOW TABLES" appdbCompare table and row counts with the source. Making the dump in the first place is covered in how to back up MySQL with mysqldump.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations