To import a MySQL database using the terminal, you can follow these steps:
- Open the terminal on your computer.
- Navigate to the directory where the SQL file you want to import is located. For example, if the file is located in the Downloads folder, you can use the command:
cd ~/Downloads
- Log in to the MySQL server using the following command:
mysql -u [username] -p
Replace [username] with your MySQL username. You will be prompted to enter your MySQL password.
- Once you are logged in to the MySQL server, create a new database using the following command:
CREATE DATABASE [database_name];
Replace [database_name] with the name of the database you want to create.
- Select the database you just created using the following command:
USE [database_name];
Replace [database_name] with the name of the database you created in the previous step.
- Import the SQL file into the database using the following command:
SOURCE [file_name.sql];
Replace [file_name.sql] with the name of the SQL file you want to import. Make sure the SQL file is located in the same directory you are currently in.
- Wait for the import process to complete. Depending on the size of the SQL file, this may take a few minutes.
That's it! You have successfully imported a MySQL database using the terminal.
No comments