MySQL

How to Import a MySQL Database using Command Line

In this tutorial, we are going to see how to import a MySQL database using Command line. To import an existing file into MySQL, you will need to create a new database. This is where the contents of the SQL file will be imported.

 

 
After you have created the database. You can import the SQL file with the following command:

mysql -u username -p db_name < file.sql
  • username : Username with which you connect to the database
  • db_name : Name of the newly created database
  • file.sql : the SQL file to import, located in the current directory

If the command is executed successfully, it will not produce any output.

If any errors occur during the process, MySQL will display them on the terminal. You can verify if the database has been imported by logging back into the MySQL shell and inspecting the data. This can be done by selecting the new database with USE db_name and then using SHOW TABLES;.
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *