Execute MySQL command on Linux via command line

Source: Internet
Author: User

There are two ways to execute SQL commands at the command line. The first is to use the "-e" parameter to specify the SQL statement that needs to be executed, and the second way is through the pipe. The syntax and examples are as follows:

1,

The code is as follows Copy Code
Mysql_home/bin/mysql-u User name-p password-d database name-e "SQL statement"
/usr/local/mysql/bin/mysql-uroot-p123456-dmysql-e "Select Host,user from User";

2,

The code is as follows Copy Code
echo "SQL statement" | Mysql_home/bin/mysql-u User name-p password-d database name
echo "Select Host,user from User" | /usr/local/mysql/bin/mysql-uroot-p123456-dmysql

The results of the above command execution are shown below. You can see from the diagram that the results of the two displays are somewhat different.

Usage scenarios are used more in scripts, such as periodic execution of stored procedures, load data infile, and deletion of old data.

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.