Web Hosting Knowledge Base Web Hosting Knowledge Base
  • Home
Get Started
Web Hosting Knowledge Base Web Hosting Knowledge Base
Get Started
Web Hosting Knowledge Base Web Hosting Knowledge Base
  • Home
loading
  1. Home
  2. Developer Corner
  3. How to import and export a MySQL database
Updated on June 23, 2024

Developer Corner

  • Folder icon closed Folder open iconDeveloper Corner Resources
    • MySQL development
      • How to connect to MySQL using Node.js
      • How to connect to MySQL using Microsoft .NET
      • How to manage MySQL databases, users, and tables from the command line
      • How to back up MySQL databases using AutoMySQLBackup
      • How to reset the MySQL root password
      • MySQL server runs out of memory or does not start
      • MySQL user privileges on shared servers
      • How to create and execute MySQL stored functions and procedures
      • Using MySQL views
      • Using MySQL triggers
      • Working with MySQL database engines
      • How to check MySQL database and table sizes
      • How to repair MySQL databases and tables
      • How to enable the slow query log in MySQL
      • How to rename a MySQL database
      • How to use indexes to improve MySQL query performance
      • How to restrict MySQL port access
      • How to install phpMyAdmin on managed hosting accounts
      • How to create a MySQL installation for local testing
      • How to troubleshoot MySQL definer issues
      • Using SELECT INTO OUTFILE in MySQL
      • How to determine the MySQL version
      • How to Fix the MySQL Error 1064
    • Ruby developer information
      • How to install Ruby Gems
      • How to use the Interactive Ruby Shell to troubleshoot gems
      • How to set up multiple versions of Ruby with the cPanel Ruby Selector
      • How to configure a Ruby on Rails application on a shared hosting account
    • Linux for the developer
      • How to manage the inode count
      • How to determine high disk usage locations
      • How to use screen
      • How to monitor resource usage
      • How to use rsync
      • How to use cURL
      • How to disable e-mail notifications from cron jobs
      • How to use ImageMagick
      • How to change the time zone in the Linux shell
      • Cron jobs reset to 15-minute intervals
      • How to install and configure Advanced Policy Firewall
      • How to configure a firewall using iptables
      • How to set the default text editor in Linux
      • How to determine a server's memory usage
      • How to generate and verify file checksums on Linux
      • How to install the EPEL repository on CentOS
      • How to run a cron job automatically after a server reboot
      • Conntrack sessions
      • How to install and configure UFW (Uncomplicated Firewall)
    • Version control systems
      • How to use Git
      • How to configure a Git client
      • How to configure Subversion (SVN)
      • How to set up Subversion (SVN) access for multiple users
      • How to use the Mercurial version control system
      • How to configure Concurrent Versions System (CVS)
      • How to configure and use a newer version of Git
      • '403 Forbidden' error message when you try to push to a GitHub repository
    • Client-side technologies
      • How to use the jQuery JavaScript library on your hosting account
      • How to install Ember.js on managed hosting accounts
      • How to use the markItUp JavaScript plugin
      • How to Use Flash on Your Website
      • Does Hostvento Hosting Support MP3 Hosting Files?
      • Hostvento Hosting MIDI (Musical Instrument Digital Interface) Support
      • How to use React on your hosting account
    • Application deployment information
      • How to install the Docker application deployment environment
      • How to install a LAMP stack on an Ubuntu server
    • How to add CAPTCHA protection to your web site
    • How to control search engines and web crawlers using the robots.txt file
    • How to set up URL frame forwarding
    • SQLite information
      • How to connect to SQLite from the command line
      • How to connect to SQLite using PHP
      • How to connect to SQLite using Python
    • Using Lua on Hostvento Hosting servers
    • How to determine if your account uses CageFS
    • How to set up a virtual machine with VirtualBox for local testing
    • Web testing and development
      • How to create a PostgreSQL installation for local testing
      • How to create an Apache installation for local testing
      • How to install development tools on an unmanaged server
    • How to create persistent Node.js applications on shared and reseller hosting accounts
    • How to enable Cross-Origin Resource Sharing (CORS)
    • How to configure frames with X-Frame-Options header
    • Developing ADA-compliant web sites
    • Nginx web server configuration
      • How to install the Nginx web server
    • How to install and configure the AWS Command Line Interface (CLI)
    • How to edit hosts file on Mac
    • How to disable automatic creation of the robots.txt file
    • How to use an SSL certificate in a Node.js app
  • Folder icon closed Folder open iconHow to enable and disable PHP error messages
  • Folder icon closed Folder open iconHow to enable PHP error logging
  • Folder icon closed Folder open iconHow to enable and disable the PHP register_globals directive
  • Folder icon closed Folder open iconHow to use the PHP magic quotes directive
  • Folder icon closed Folder open iconHow to change the PHP time zone setting
  • Folder icon closed Folder open iconHow to enable and disable the PHP allow_url_fopen directive
  • Folder icon closed Folder open iconPHP max_execution_time Guide
  • Folder icon closed Folder open iconHow to change the maximum upload file size for PHP scripts
  • Folder icon closed Folder open iconHow to connect to MySQL from the command line
  • Folder icon closed Folder open iconHow to connect to MySQL using PHP
  • Folder icon closed Folder open iconHow to connect to MySQL using Perl
  • Folder icon closed Folder open iconHow to import and export a MySQL database
  • Folder icon closed Folder open iconHow to set up a remote MySQL connection
  • Folder icon closed Folder open iconUsing MySQL client applications
  • Folder icon closed Folder open iconHow to convert a MySQL database to UTF-8 encoding
  • Folder icon closed Folder open iconHow to convert the time zone in MySQL
  • Folder icon closed Folder open iconHow to back up MySQL databases using cron jobs
  • Folder icon closed Folder open iconInformation schema database in MySQL
  • Folder icon closed Folder open iconHow to connect to PostgreSQL using psql
  • Folder icon closed Folder open iconHow to connect to PostgreSQL using PHP
  • Folder icon closed Folder open iconHow to connect to PostgreSQL using Perl
  • Folder icon closed Folder open iconHow to import and export a PostgreSQL database
  • Folder icon closed Folder open iconHow to set up a remote PostgreSQL connection
  • Folder icon closed Folder open iconHow to use .htaccess files
  • Folder icon closed Folder open iconHow to change the default directory index page using an .htaccess file
  • Folder icon closed Folder open iconHow to enable and disable directory index listings using an .htaccess file
  • Folder icon closed Folder open iconHow to enable data compression using the mod_deflate module
  • Folder icon closed Folder open icon'403 Forbidden' error message
  • Folder icon closed Folder open iconHow to enable pathname information in URLs using the AcceptPathInfo directive
  • Folder icon closed Folder open iconHow to troubleshoot CGI scripts
  • Folder icon closed Folder open iconWhat is PHP?
  • Folder icon closed Folder open iconPHP script basics
  • Folder icon closed Folder open iconHow to view PHP settings with the phpinfo() function
  • Folder icon closed Folder open iconControlling PHP settings with a custom php.ini file
  • Folder icon closed Folder open iconUsing php.ini directives
  • Folder icon closed Folder open iconHow to run PHP scripts from cron jobs
  • Folder icon closed Folder open iconSetting the PHP include path
  • Folder icon closed Folder open iconHow to determine if a PHP function is available
  • Folder icon closed Folder open iconHow to fix '500 Internal Server Error' while running PHP
  • Folder icon closed Folder open iconPython script basics
  • Folder icon closed Folder open iconPerl script basics
  • Folder icon closed Folder open iconHow to troubleshoot Perl scripts
  • Folder icon closed Folder open iconHow to use the shebang
  • Folder icon closed Folder open iconPostgreSQL development
    • How to connect to PostgreSQL using Python
    • How to use PostgreSQL client applications
    • How to back up PostgreSQL databases using cron jobs
    • How to manage PostgreSQL databases and users from the command line
    • How to determine the PostgreSQL and PostGIS versions
    • How to determine the size of PostgreSQL databases and tables
    • How to rename a PostgreSQL database
    • ECCN and HTS numbers for PostgreSQL
  • Folder icon closed Folder open iconApache web server configuration
    • How to change the document root directory
    • How to add or remove the www prefix in domain URLs
    • How To Use Apache Access Log & Apache Error Log
    • How to rewrite URLs in Apache with the mod_rewrite module
    • How to use Server-Side Includes (SSI)
    • How to use the mod_speling Apache module
    • How to modify HTTP headers using .htaccess files
    • How to configure caching with the mod_expires module
    • How to disable entity tags (ETags)
    • How to use keep-alive connections to improve performance
    • How to control site access based on a visitor's country
    • How to turn off caching using .htaccess
    • How to install Apache Tomcat
    • How to protect a website folders using .htaccess
  • Folder icon closed Folder open iconPHP development resources
    • How to change PHP settings and versions on managed hosting accounts
    • How to set up custom .htaccess files for PHP settings
    • Using PHP directives in custom .htaccess files
    • Using PHP to send e-mail messages
    • How to install and configure PEAR packages
    • How to troubleshoot 'String could not be parsed as XML' error message in PHP
    • How to use the Exif extension in PHP
    • How to resolve some common issues after a PHP upgrade
    • How to use a custom php.ini file for cPanel cron jobs
    • How To Use PHP Sessions
    • ionCube PHP Loader support
    • How to specify the MySQL character set in PHP
    • How to fix the 'Unable to allocate memory for pool' PHP error
    • How to optimize Symfony using APC
    • How to use the internationalization (intl) extension in PHP
    • How to install PHP composer
    • How to determine if APC is installed on a server
    • How to use the MailChimp API with PHP
    • 'Allowed memory size exhausted' error message in PHP
    • How to use ionCube Loader with different PHP versions
    • How to enable PHP opcode caching
    • How to send e-mail using PHPMailer
    • How to harden PHP 7 and earlier versions using cPanel
    • Custom PHP settings per directory with .user.ini files
    • ionCube PHP Loader unavailable on PHP 8.0
    • How to change the PHP version for a specific directory
  • Folder icon closed Folder open iconPython
    • How to use virtualenv and pip
    • How to activate a Python virtual environment from a script file
    • How to send e-mail messages using Python
    • How to configure and use a newer version of Python
    • How to install and configure Django on unmanaged servers
    • How to install and configure Django on a Linux shared hosting account
    • How to install and configure Flask on a Linux shared hosting account
    • How to install FastAPI on unmanaged servers
  • Folder icon closed Folder open iconPerl Information Overview

How to import and export a MySQL database

Estimated reading: 7 minutes 182 views

This article describes how to import MySQL databases and export MySQL databases. You can import and export databases for a variety of scenarios, including:

Transferring a MySQL database from one web hosting account or provider to another.

Importing a third-party MySQL database.

Backing up a MySQL database

How to export a MySQL database

You can export a MySQL database to a file by using phpMyAdmin or the mysqldump table/database command line program.

Method #1: Use phpMyAdmin

You can export a MySQL database using the phpMyAdmin web interface. To do this, follow these steps:

  1. Log in to cPanel.If you do not know how to log in to your cPanel account, please see this article.
  2. In the DATABASES section of the cPanel home screen, click phpMyAdmin:cPanel - Databases - phyMyAdmin iconThe phpMyAdmin administration page appears in a new window.
  3. In the left pane of the phpMyAdmin page, click the database that you want to export.
  4. Click the Export tab.
  5. Under Export method, confirm that Quick is selected.
    If you are using an older version of phpMyAdmin that does not have the Quick option, follow these steps instead:
    • In the Export section, click Select All.
    • Select the Save as file checkbox, and then click Go. The export process runs.
  6. Under Format, confirm that SQL is selected.
  7. Click Go.
  8. In the Save File dialog box, type the filename and select the directory where you want to save the exported database on your local computer.
  9. Click Save. The export process runs.
Method #2: Use the mysqldump table program

You can export a MySQL database from the command line using the mysqldump table/database program. To do this, follow these steps:

  1. Access the command line on the computer where the database is stored. For example, if the database is on another web hosting account or with another web hosting provider, log in to the account using SSH. If you have physical access to the computer, you can open a DOS or terminal window to access the command line.
  2. Type the following command, and then press Enter. Replace username with your username, and dbname with the name of the database that you want to export:Copymysqldump –routines -u username -p dbname > dbexport.sql This example uses the dbexport.sql filename for the exported database, but you can name the file whatever you want.
  3. Type your password at the Enter password prompt.
  4. The dbexport.sql file now contains all of the data for the dbname database. If the dbexport.sql file is on a remote computer, download the file to your local computer.

Creating a new MySQL database and assigning a user

Before you can import the database, you must create a new database in cPanel and assign a user to it. To do this, follow these steps:

  1. Log in to cPanel.If you do not know how to log in to your cPanel account, please see this article.
  2. In the DATABASES section of the cPanel home screen, click MySQL® Databases:cPanel - MySQL Databases icon
  3. Under Create New Database, in the New Database text box, type the name of the database.
  4. Click Create Database. cPanel creates the database.
  5. When the database is created, click Go Back.
  6. Under Add User to Database, in the User list box, select the user that you want to add.
  7. In the Database list box, select the new database.
  8. Click Add.
  9. Select the check boxes to grant the user specific privileges, or select the ALL PRIVILEGES check box to grant the user all permissions to the database.
  10. Click Make Changes. cPanel adds the user to the database.

How to import a MySQL database

After you have created a new database in cPanel, you can import the database’s contents by using phpMyAdmin or the mysql command line program.

If the exported database file contains any CREATE DATABASE statements, you must remove them or comment them out. Otherwise, the import process will fail.

Method #1: Use phpMyAdmin

You can import a MySQL database using the phpMyAdmin web interface. To do this, follow these steps:

  1. Log in to cPanel.If you do not know how to log in to your cPanel account, please see this article.
  2. In the DATABASES section of the cPanel home screen, click phpMyAdmin:cPanel - Databases - phyMyAdmin iconThe phpMyAdmin administration page appears in a new window.
  3. In the left pane of the phpMyAdmin page, click the database that you want to import the data into.
  4. Click the Import tab.
  5. Under File to Import, click Browse, and then select the dbexport.sql file on your local computer.
  6. Click Go. The import process runs.
  7. The database should now contain the data that is in the dbexport.sql file.
Method #2: Use the mysql program

You can import a MySQL database from the command line using the mysql program. To do this, follow these steps:

  1. Transfer the dbexport.sql file to your Hostvento Hosting account using SCP, SFTP, or FTP.
  2. Log in to your Hostvento Hosting account using SSH.
  3. Change to the directory where you uploaded the dbexport.sql file. For example, if you uploaded the dbexport.sql file to your home directory, type cd ~.
  4. Type the following command, and then press Enter. Replace username with your username and dbname with the name of the database that you want to import the data into:Copymysql -u username -p dbname < dbexport.sql
  5. The dbname database should now contain the data that is in the dbexport.sql file.
Troubleshooting a MySQL database import

You may receive one of the following error messages when you try to import a MySQL database using either phpMyAdmin or the mysql program:

  • ERROR 1044: Access denied for user ‘username1’@’localhost’ to database ‘username2_database’
  • This error message occurs when the import file contains an SQL statement that attempts to access a database for the wrong username. Note in this example that username2 in username2_database does not match username1 in ‘username1’@’localhost’. You must edit the import file and change username2 to your new username1.
  • ERROR 1049: Unknown database ‘username_database’
  • This error message occurs when the target database does not exist. Make sure you create the database first as described above, and then try to it import again.
  • ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘username_database’ at line x.
  • This error message occurs when the import file does not contain backup data for a database or there is a MySQL syntax error in the file. Alternatively, the import file may be altered, corrupt, or in an unsupported format. (Import files must contain SQL statements; other file formats such as CSV do not work with the mysql program.) Try exporting the database again, and then try to import it.
  • ERROR 1227: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
  • This error message occurs when the import file contains one or more SQL statements that require superuser privileges (such as SET GLOBAL or CREATE DEFINER statements). In some cases, you can just delete these statements from the .sql file and rerun the import process. For example, CREATE DATABASE statements can be safely removed, because you should have already created the database in cPanel. If you require MySQL superuser access, however, you should consider migrating your account to a VPS or Dedicated server, where you have complete control over the environment. For more information about MySQL user privileges on shared servers.

Still stuck? How can we help?

How can we help?

Was this page helpful? Yes No

Share this Doc

How to import and export a MySQL database

Or copy link

Clipboard Icon
CONTENTS
Leaf Illustration

© 2023 All Rights Reserved by Hostvento