Your destination for complete Tech news

how to import an SQL file using the command line in MySQL?

24 0
< 1 min read

To import an SQL file using the command line in MySQL, you can use the mysql command-line client with the -u and -p options to specify the username and password for your MySQL server, and the -h option to specify the hostname of the server.

Here’s an example of how to import an SQL file using the command line in MySQL:

mysql -u username -p -h localhost database_name < file.sql

In this example, we use the mysql command-line client to connect to the MySQL server running on localhost with the specified username and password, and select the database_name database. Then, we use the < operator to redirect the contents of the file.sql file into the mysql command-line client as input.

The mysql command-line client will execute the SQL statements in the file.sql file in the selected database.

Note: If you are prompted for a password, you will need to enter the password for the username specified in the command.

You can also use the mysql command-line client with the -f option to force the client to continue even if errors are encountered while executing the SQL statements in the file.sql file:

mysql -u username -p -h localhost database_name -f < file.sql

This can be useful if you want to import an SQL file that contains multiple SQL statements and you want to continue executing the remaining statements even if some of the statements fail.

Leave A Reply

Your email address will not be published.

eight + 2 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.