Execute MySQL Scripts on the Command Line

When working with MySQL it is often necessary to execute SQL statements or scripts programmatically from the command line. SQL statements can be included in a SQL script (text) file and executed by the MySQL Client. This can be done in a few different ways.

Execute MySQL Script File from Standard Input

Statements in a SQL scripts can be read from standard input on a Unix/Linux command line and executed. Two examples of doing this can be seen below.

Execute MySQL Script File from MySQL Shell

While running the MySQL shell, SQL scripts can be executed using the source or \. commands.

Using the --verbose Option

Using the --verbose option when executing MySQL scripts on the command line will print the individual SQL statements before the are executed.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">