Your website's most valuable asset is usually its database: members, orders, posts, settings... In this guide we explain how to safely back up, compress and restore MySQL and MariaDB databases with mysqldump, what to watch out for with large databases, and the phpMyAdmin method.
What is mysqldump?
mysqldump is a tool that exports a database's structure and data as SQL statements into a file. It ships with MySQL and MariaDB, so no extra installation is needed. The resulting .sql file can be moved to another server and used to recreate the same database.
Backing up a single database
mysqldump -u kullanici -p --single-transaction --routines --triggers --default-character-set=utf8mb4 veritabani_adi > veritabani_adi.sql| Parameter | What does it do? |
|---|---|
-p | Prompts for the password securely (don't type it into the command). |
--single-transaction | Takes a consistent backup of InnoDB tables while the site is running, without locking tables. |
--routines --triggers | Also includes stored procedures and triggers in the backup. |
--default-character-set=utf8mb4 | Prevents non-ASCII characters (such as Turkish letters) and emojis from being corrupted. |
Backing up with compression
Since SQL files are text, they compress very well; the size often drops to a tenth:
mysqldump -u kullanici -p --single-transaction veritabani_adi | gzip > veritabani_adi-$(date +%F).sql.gzBacking up all databases
sudo mysqldump --all-databases --single-transaction --routines --events | gzip > tum-veritabanlari-$(date +%F).sql.gzTo back up a few specific databases:
mysqldump -u root -p --databases site1 site2 > secili.sqlStructure only or data only
# Table structures only (no data)
mysqldump -u kullanici -p --no-data veritabani_adi > yapi.sql
# Data only (no table creation statements)
mysqldump -u kullanici -p --no-create-info veritabani_adi > veri.sql
# A single table
mysqldump -u kullanici -p veritabani_adi wp_posts > wp_posts.sqlRestoring
Before restoring, make sure the target database exists:
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS veritabani_adi CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"Then import the backup:
# Uncompressed backup
mysql -u kullanici -p veritabani_adi < veritabani_adi.sql
# .gz backup
gunzip < veritabani_adi-2026-10-20.sql.gz | mysql -u kullanici -p veritabani_adiRestoring overwrites the contents of tables with the same names. Before restoring into a live database, take a backup of its current state as well.
Tips for large databases
- Run the import inside
screenortmuxso it isn't interrupted if your SSH session drops. - You can use the
pvtool to see progress:pv yedek.sql.gz | gunzip | mysql -u kullanici -p veritabani_adi - If you get the "MySQL server has gone away" error, increase the
max_allowed_packetvalue in the server configuration (e.g.256M). - For very large databases (tens of GB), physical backup tools such as Percona XtraBackup or MariaDB's
mariabackupare faster.
Backing up and restoring with phpMyAdmin
If you don't have SSH access (shared hosting), you can use phpMyAdmin in cPanel:
- Open phpMyAdmin in cPanel and select your database on the left.
- On the Export tab, choose Quick as the method and SQL as the format, then click Go.
- To restore, select the target database and upload the file on the Import tab.
phpMyAdmin has a file upload limit. If the import fails for a large file, compress it as .zip or .gz before uploading, or use the mysql command on a server with SSH access.
Automate your backups
Manual backups get forgotten over time. To take database backups automatically every night, delete old ones and copy them to a remote server, follow our Linux automatic backup guide.
Common errors
Special characters show up as "?" or garbled
Make sure the character set is utf8mb4 both when backing up and when restoring. Also create the target database with utf8mb4_unicode_ci.
"Access denied" error
Make sure the user has privileges on the database in question. In cPanel, database usernames usually start with the cpanelkullanici_ (cPanel username) prefix.
Conclusion
With mysqldump, a few commands are enough to take reliable database backups and restore them within minutes. For database-heavy projects, VDS servers with NVMe SSDs and Ryzen 9 performance servers with high single-core performance noticeably shorten query times.
Frequently Asked Questions
Is it safe to take a backup while the site is live?
With InnoDB tables, you can take a consistent backup while the site is running by using the --single-transaction parameter. With MyISAM tables, brief locking may occur.
I can't upload a large database with phpMyAdmin. What should I do?
Import files that exceed phpMyAdmin's upload limit directly over SSH with the mysql command; this method has no size limit.
Which character set should the backup file use?
To keep non-ASCII characters such as Turkish letters from being corrupted, use utf8mb4 and add the --default-character-set=utf8mb4 parameter to the mysqldump command.
