Documentation Home
MySQL 9.5 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.4Mb
PDF (A4) - 41.5Mb
Man Pages (TGZ) - 272.3Kb
Man Pages (Zip) - 378.2Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.5 Reference Manual  / ...  / MySQL Programs  / Client Programs  / mysql — The MySQL Command-Line Client  /  Executing SQL Statements from a Text File

6.5.1.5 Executing SQL Statements from a Text File

Themysql client typically is used interactively, like this:

mysqldb_name

However, it is also possible to put your SQL statements in a file and then tellmysql to read its input from that file. To do so, create a text filetext_file that contains the statements you wish to execute. Then invokemysql as shown here:

mysqldb_name <text_file

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

mysql < text_file

If you are already runningmysql, you can execute an SQL script file using thesource command or\. command:

mysql> sourcefile_namemysql> \.file_name

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 invokemysql 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 error. Presence of a BOM does not causemysql to change its default character set. To do that, invokemysql with an option such as--default-character-set=utf8mb4.

For more information about batch mode, seeSection 5.5, “Using mysql in Batch Mode”.