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. Howto Convert Text File From UTF-8 to ISO-8859-1 Encoding
  3. MDB Tools to export (migrate) from mdb (Microsoft Access format) to MySQL
  4. Bash shortcuts tips and tricks
  5. Sun acquires MySQL
  6. Sending Spam with SWT
  7. Optimize MySQL for Low Memory Use
  8. Troubleshooting PHP Sqlite Query Error: Unable to open database
  9. Slow Query Log Analyzes Tools
  10. dos2unix on Ubuntu and Debian

Popular Related Items »

Leave a Comment