Summary of several ways to execute SQL in the Mysql command line _mysql

Source: Internet
Author: User
Tags mysql in mysql command line

1. Direct Input SQL execution

Mysql> Select Now ();
+---------------------+
| Now () |
+---------------------+
| 2013-09-18 13:55:45 |
+---------------------+
1 row in Set (0.00 sec)

2. Execute the prepared SQL script

Mysql> Source H:/1.sql
+---------------------+
| Now () |
+---------------------+
| 2013-09-18 13:54:04 |
+---------------------+
1 row in Set (0.00 sec)

3.select. into outfile Execute SQL

Mysql> Select Now () into outfile ' h:/data/2.sql ';
Query OK, 1 row Affected (0.00 sec)

4. Use the MySQL command to execute

H:\>mysql-uahmin-p-E "Select Now"
Enter PASSWORH: * * *
+---------------------+
| Now () |
+---------------------+
| 2013-09-18 13:57:09 |
+---------------------+

The 5.mysql command executes SQL and saves the results of the query to text

A) Execute simple SQL

Mysql-uahmin-proot test-e "Select Now ()" N >h:/work/target1.txt
If the SQL is very long, this approach is not very appropriate.

b) executing complex SQL

Complex SQL 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

The last execution mode plus the operating system timing tasks, you can implement the scheduled execution of SQL in MySQL, and save the purpose of execution results.

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

The above is a small series for everyone to bring the MySQL command line in the execution of SQL several ways to summarize all the content, I hope that we support cloud-Habitat Community ~

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.