Summary of several ways to execute SQL in mysql command line, mysqlsql

Source: Internet
Author: User
Tags mysql command line

Summary of several ways to execute SQL in mysql command line, mysqlsql

1. directly input SQL to execute

MySQL> select now ();
+ --------------------- +
| Now () |
+ --------------------- +
| 13:55:45 |
+ --------------------- +
1 row in set (0.00 sec)

2. Execute the compiled SQL script

Mysql> source H:/1. SQL
+ --------------------- +
| Now () |
+ --------------------- +
| 13:54:04 |
+ --------------------- +
1 row in set (0.00 sec)

3. select... into outfile method to execute SQL

Mysql> select now () into outfile 'H:/data/2. SQL ';
Query OK, 1 row affected (0.00 sec)

4. Run the mysql Command

H: \> mysql-uaHmin-p-e "select now ()"
Enter passworH :****
+ --------------------- +
| Now () |
+ --------------------- +
| 13:57:09 |
+ --------------------- +

5. Run the mysql command to execute the SQL statement and save the query result to the text.

A) execute simple SQL

Mysql-uaHmin-proot test-e "select now ()"-N> H:/work/target1.txt
If the SQL statement is too long, this method is not very suitable.

B) execute complex SQL statements

Complex SQL statements can be edited in advance and stored in text for execution.
H: \> mysql-uroot-pmypwH-h127.0.0.1-p3306 test <H:/work/source. SQL> H:/work/target.txt

By adding the last execution method to the scheduled task of the operating system, you can implement scheduled SQL Execution in mysql and save the execution results.

Reference: 3.5. Using mysql in Batch Mode in the official documentation
Http://dev.mysql.com/doc/refman/5.6/en/batch-mode.html

The above is a summary of all the methods for executing SQL statements in the mysql command line provided by xiaobian. I hope you can support more help ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.