How do I execute a SQL script file on the command line in MySQL?

Source: Internet
Author: User

Requirements Description :

In the use of MySQL database, sometimes you need to execute a SQL script file directly on the Shell's command line,

For example, to initialize a database, create a specific stored procedure, create a table, and so on, perform a basic test.

In general, MySQL is logged in interactively, executing SQL statements. All you have to do is put SQL in a file and let MySQL

Client program to execute.

Operation Process :

1. Create a SQL script text file that contains the SQL statement you want to execute

 Use test01 Select Count (* from ts051;

Note: The file name of the SQL script, Secount.sql,use specifies the name of the database.

2. In the shell command line, invoke the MySQL command to execute the SQL script

< secount.sql Enter Password:   #输入root用户的密码. count (*)557107

Note: On the command line, to specify the user to connect to the database, you do not need to specify the database you want to use with the-D parameter in the script if you indicate the database to be used by using the.

Summary :

In the command line, execute the script by invoking the MySQL command, and then using the < less than sign to input the contents of the SQL script.

Document creation time: March 20, 2018 11:28:17

How do I execute a SQL script file on the command line in MySQL?

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.