Executing SQL statements from a text file in DBMS MySQL

How do work with a text files in clien of DBMS ?
The mysql client typically is used interactively, like this:

> mysql _name

However, it is also possible to put your statements in a file and then tell mysql to read its input from that file. To do so, a text file text_file that contains the statements you wish to execute. Then invoke mysql as shown here:

shell> mysql db_name < text_file

If you place a USE db_name statement as the first statement in the file, it is unnecessary to specify the database name on the command line:

shell> mysql < text_file

If you are already running mysql, you can execute an SQL script file using the command or \. command:

mysql> source file_name
mysql> \. file_name

Operator «source» don’t common SQL language operator, this only inbuilt in DBMS MySQL operator.

Sometimes you may want your script to display progress information to the user. For this you can insert statements like this:

SELECT '<info_to_display>' AS ' ';

The statement shown outputs <info_to_display>.

You can also invoke mysql with the —verbose option, which causes each statement to be displayed before the result that it produces.

MySql ignores Unicode byte order mark (BOM) characters at the beginning of input files. Previously, it read them and sent them to the server, resulting in a syntax . Presence of a BOM does not cause mysql to change its default character set. To do that, invoke mysql with an option such as --default-character-set=utf8.


Simple import sql dump into database with help source operator:

mysql> source db.sql;
Tags: , , , , , , , , , ,

6.98MB | MySQL:54 | 0,059sec