Exporting and importing a MySQL database is a common task during website migration, staging to production releases, backups, or when moving an application to a new hosting account. In a managed hosting environment, this process is usually done through a control panel such as Plesk, phpMyAdmin, or by using the command line for larger databases. Done correctly, it helps you move data safely, reduce downtime, and reconnect your application with minimal disruption.
If you are moving a website in an EU hosting environment, it is important to plan the database transfer carefully. A MySQL database often contains content, user accounts, settings, orders, and session data. Any mismatch between the exported file, the import method, and the application configuration can cause broken logins, missing content, or connection errors after the move.
When you need to export and import a MySQL database
You typically export and import a MySQL database when:
- moving a website to a new hosting platform or new account
- cloning a site for staging, testing, or development
- restoring data from a backup
- switching from one control panel to another
- reconnecting an application after a migration
- upgrading to a new server with better performance
In migration projects, the database is often the most sensitive part of the move. Files can usually be copied directly, but the database must be exported in a consistent format and imported into the target environment with the correct user permissions and connection settings.
Before you start: what to check first
Before exporting a database, confirm a few basic details. This prevents common import problems later.
Check the database name and size
Make sure you know the exact database name, the associated user, and the approximate database size. Large databases may not import reliably through a browser-based tool and may require command-line import or a split backup file.
Confirm the database engine and version
This article applies to MySQL databases, but many hosting platforms also support MariaDB. In most cases, MySQL dumps can be imported into compatible MariaDB environments, but version differences may affect SQL syntax, character sets, or table engine settings.
Put the site into maintenance mode if needed
If the database is active and changing constantly, consider putting the application in maintenance mode during the export. This is especially important for e-commerce sites, membership portals, and any application that writes new data during the migration window.
Check available disk space
On the target account, verify that there is enough disk space for both the imported database and the temporary SQL file. Insufficient space can interrupt the import and leave the database partially populated.
Back up everything before making changes
Always keep a fresh backup of the source database and any related application files. If something goes wrong during import, you can restore the original state and try again without data loss.
How to export a MySQL database
There are several reliable ways to export a MySQL database. The right method depends on the size of the database, your access level, and the tools available in your hosting control panel.
Export using phpMyAdmin
phpMyAdmin is one of the most common tools in hosting environments. It is suitable for small and medium databases.
- Log in to your hosting control panel and open phpMyAdmin.
- Select the database you want to export from the left-hand sidebar.
- Open the Export tab.
- Choose Quick export for a simple download, or Custom if you need more options.
- Select the format as SQL.
- If available, enable options such as DROP TABLE / VIEW / PROCEDURE / FUNCTION to make future restores cleaner.
- Choose compression if the database is large, such as gzip or zip.
- Download the file to your computer.
For most migrations, an SQL export is the safest choice because it preserves table structure and data in a form that can be imported again easily.
Export using the control panel database tools
Some hosting platforms provide database backup or export tools directly in Plesk or a similar control panel. These tools may allow you to generate a dump file without opening phpMyAdmin.
Typical steps include:
- open the database management section
- select the required database
- choose backup or export
- download the resulting SQL file or archive
If your platform offers built-in database backups, they are often convenient for routine administration. However, for migration between accounts or platforms, an SQL dump is usually more portable.
Export using the command line
For larger databases or more advanced migrations, command-line export is more efficient and reliable than a browser tool. The common utility is mysqldump.
A typical export command looks like this:
mysqldump -u db_user -p db_name > db_name.sql
After entering the password, the database contents are written to an SQL file. On managed hosting platforms, SSH access may be available for this purpose. Command-line export is recommended when:
- the database is large
- phpMyAdmin times out
- you need better control over the dump process
- you are moving multiple databases
Useful export options
Depending on the application, you may want to include the following in the export:
- Structure and data — needed for a full migration
- Triggers — important for some applications and automation
- Stored procedures and functions — used by advanced applications
- Routines — helpful for systems with custom database logic
If you are exporting a database for a CMS, shop, or custom application, it is usually best to export the entire database rather than selected tables, unless you have a specific reason to do otherwise.
How to import a MySQL database
Once you have the SQL file, import it into the target database on the new hosting account or server. Before you import, create the destination database and database user if they do not already exist.
Create the target database and user
In the control panel, create:
- a new MySQL database
- a database user with a secure password
- the necessary permissions for that user to access the database
Without the correct permissions, your application may connect to the database server but still fail to read or write data.
Import using phpMyAdmin
phpMyAdmin is suitable for smaller imports and is usually the simplest method.
- Open phpMyAdmin in the target hosting account.
- Select the destination database.
- Open the Import tab.
- Choose the SQL file from your computer.
- Confirm the format is SQL.
- Start the import and wait for completion.
If the file is compressed, phpMyAdmin may be able to handle it directly. If not, decompress it first before importing.
Import using the command line
For larger databases, command-line import is usually more stable. Use the mysql client utility:
mysql -u db_user -p db_name < db_name.sql
This method is less likely to time out and is generally preferred for databases that are too large for browser-based uploads.
Import from a compressed file
If the SQL dump is compressed, you may need to decompress it before importing, depending on your tools. In some cases, the import can be piped directly on the command line. This is useful when working with large backups and limited disk space.
Always verify that the file was created completely and is not corrupted before importing it to production.
How to reconnect your application after import
Importing the database is only part of the migration. The application must also point to the new database correctly. This step is often where connection errors appear after a move.
Update the database configuration file
Most applications store database connection settings in a configuration file. Update the following values as needed:
- database name
- database username
- database password
- database host
- table prefix, if used
Common configuration file names vary by platform, but the principle is the same: the application must match the new database credentials and host information from the target hosting environment.
Check the database host value
In many hosting setups, the database host is localhost, but not always. Some managed hosting platforms use a different internal hostname or a remote database endpoint. If the site shows a connection error after import, verify the database host first.
Verify file and database ownership if applicable
On some hosting setups, permissions and ownership can affect whether the application can read its configuration file or connect to the database properly. If you migrated files manually, ensure the web server user has the expected access.
Test the site thoroughly
After reconnecting the database, test:
- homepage loading
- login and logout
- forms and contact pages
- search functionality
- checkout or payment flows, if applicable
- admin dashboard access
For CMS platforms and web shops, missing database tables, incorrect prefixes, or incomplete imports can show up only when specific features are used.
Common problems during export and import
Database migration issues usually fall into a few predictable categories. Knowing them in advance can save time.
Import fails because the file is too large
Browser-based tools often have upload or timeout limits. If the SQL file is large, use SSH and the command line, or split the dump into smaller parts. Compressing the export may also help reduce transfer time.
Character encoding looks broken
If special characters, accents, or non-English text appear corrupted, the issue may be related to character set or collation. Confirm that the export and import use compatible settings, such as UTF-8 or utf8mb4 where appropriate.
Database connection error after migration
This usually means one of the following:
- incorrect database name
- wrong username or password
- database user not assigned to the database
- wrong database host
- configuration file not updated after the move
Some tables are missing
If only part of the database was imported, check whether the export was complete. A partial export or interrupted import can leave the application unusable. Re-import a full backup after confirming the export file is intact.
Permissions errors appear in the application
This can happen if the database user was created but not granted sufficient privileges. Ensure the user has the correct permissions for the intended application. For most website migrations, full privileges on the application database are required.
Triggers or routines are missing
If your application uses stored procedures, functions, or triggers, make sure these were included in the export. Some export tools exclude them by default unless you enable the relevant options.
Best practices for a safer migration
Following a few simple practices makes export and import much safer, especially when hosting websites in Europe where planned migration windows are often used to reduce downtime.
- take a fresh backup before starting
- export during a low-traffic period
- use a consistent naming scheme for databases and users
- test the import on staging before going live
- keep the old database available until the new site is confirmed working
- record the original connection settings in case you need to roll back
If possible, validate the exported SQL file before import. Even a small corruption in the file can stop the import halfway through.
Example migration workflow
A practical database migration usually follows this order:
- create a backup of the source site and database
- export the MySQL database as an SQL file
- upload or transfer the file to the new hosting account
- create the target database and database user
- import the SQL file into the new database
- update the application configuration with the new credentials
- test the website and database connection
- switch DNS or go live after validation
This workflow works well for many common platforms, including CMS-based websites and custom applications hosted in a managed environment.
FAQ
What is the difference between exporting and backing up a MySQL database?
An export usually creates a portable SQL file that can be imported elsewhere. A backup may use the same file format, but the term often refers to a broader recovery process. For migration, the exported SQL file is the key artifact.
Can I import a MySQL database into a new account without changing the website files?
Not usually. The website files must point to the new database name, username, password, and host. Importing the database alone does not update the application configuration.
Why does phpMyAdmin fail on large databases?
phpMyAdmin runs through the browser, so it can hit upload limits, execution timeouts, or memory limits. For larger databases, command-line import is often more reliable.
Should I compress the database export?
Yes, compression can reduce transfer size and speed up downloads and uploads. It is especially helpful for larger databases, but make sure your import tool can handle the chosen format.
What if the site shows errors after the import?
Check the database credentials first, then verify the database host, user permissions, table prefix, and whether the import completed fully. If needed, restore the backup and repeat the process carefully.
Can I move a database between MySQL and MariaDB?
Often yes, but compatibility depends on the version and the SQL features used by the application. Test the import on a staging environment before moving a live site.
Conclusion
Exporting and importing a MySQL database is a standard part of website migration, backup recovery, and application deployment. In a hosting environment, the most reliable approach is to export a complete SQL dump, create the target database and user, import the file, and then update the application’s connection settings. For smaller databases, phpMyAdmin is often enough. For larger or more complex migrations, command-line tools are usually more stable.
Careful preparation, a verified backup, and post-migration testing reduce the risk of downtime and data loss. If you are moving a site in an EU hosting setup, plan the database transfer as part of the full migration process so that files, configuration, and DNS changes all line up smoothly.