Executing SQL Statements from a Text File

The mysql client typically is used interactively, like this:

debian1:~# mysql db_name

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

debian1:~# 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:

debian1:~# mysql < text_file

From the MySQL Manual

Related posts:

  1. Howto: How to Reset the MySQL Root Password
  2. MDB Tools to export (migrate) from mdb (Microsoft Access format) to MySQL
  3. Howto Convert Text File From UTF-8 to ISO-8859-1 Encoding
  4. Bash shortcuts tips and tricks
  5. Sun acquires MySQL
  6. Optimize MySQL for Low Memory Use
  7. Sending Spam with SWT
  8. Slow Query Log Analyzes Tools
  9. Troubleshooting PHP Sqlite Query Error: Unable to open database
  10. Combine Multiple PDFs Into One File

Popular Related Items »

Leave a Comment