Add / Import .SQL file To MySQL Database Server

To import a SQL file into a MySQL database server, you can use the mysql command-line client. The basic syntax is as follows:

mysql -u [user] -p [database] < [filename.sql]

Where:

  • [user] is the MySQL username with sufficient privileges to import the database.
  • [database] is the name of the database you want to import the SQL file into.
  • [filename.sql] is the name of the SQL file you want to import.

Here’s an example that imports a file named backup.sql into a database named mydatabase using the root user:

mysql -u root -p mydatabase < backup.sql

You will be prompted for the password of the MySQL user. Once you enter the password, the SQL commands in the file will be executed, and the database will be imported.

Note: The SQL file should contain only valid SQL commands, such as CREATE, INSERT, UPDATE, DELETE, etc. If the SQL file contains errors, they will be displayed on the command-line, and the import process will be terminated. (https://www.christophechoo.com/)

Leave a Comment