Our Help Portal

Troubleshooting Support Articles
Searchable Help Information Repository
Self-Service Resources How-Tos
Technical Customer Walkthroughs   Browse All Knowledge ! ....

Get Prices Learn More

Breaking

< All Topics
Print

How do I import a MySQL Database?

Importing a MySQL database involves restoring the database from a previously exported file. The process can be done using the mysql command in the command line or through tools like phpMyAdmin. Here are the steps for both methods:

Using Command Line (mysql):

  1. Open a Command Prompt or Terminal:
    • On Windows, you can open the Command Prompt.
    • On macOS or Linux, use the Terminal.
  2. Navigate to MySQL Bin Directory (Optional):
    • If the MySQL bin directory is not in your system’s PATH, navigate to it using the cd command.
  3. Run the mysql Command:
    • Use the following command to import the MySQL database. Replace database_name with the name of your database, and provide the appropriate MySQL username and password.

bash
mysql -u username -p database_name < backup.sql

  • If the MySQL server is running on the local machine, you may omit the -u and -p options to use the default user and prompt for the password.
  • After running this command, you’ll be prompted to enter the MySQL user password. Once entered, the database will be imported from the backup.sql file.

Using phpMyAdmin (Web-based):

  1. Access phpMyAdmin:
    • Log in to your phpMyAdmin interface through your web browser.
  2. Select the Database:
    • Click on the database where you want to import the data from the left-hand navigation panel.
  3. Choose Import:
    • Navigate to the “Import” tab.
  4. Select File to Import:
    • Click on the “Choose File” button and select the SQL file you want to import.
  5. Initiate Import:
    • Click the “Go” or “Import” button to start the import process.
    • phpMyAdmin will read the SQL file and execute the statements to recreate the database.
  6. Review and Confirm:
    • Review the import settings, and if everything looks correct, confirm the import.

The method you choose depends on your preference and the tools available to you. The command-line method is often preferred for larger databases or automation, while phpMyAdmin provides a user-friendly interface for smaller databases. Ensure that you have a backup of your database before performing an import, especially if you are making significant changes.

Categories