Knowledge Base Portal Help
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):
- Open a Command Prompt or Terminal:
- On Windows, you can open the Command Prompt.
- On macOS or Linux, use the Terminal.
- 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.
- If the MySQL bin directory is not in your system’s PATH, navigate to it using the
- 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.
- Use the following command to import the MySQL database. Replace
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.