How to operate MySQL using Linux Shell

Source: Internet
Author: User

MySQL provides rich operation interfaces for other programming languages. Generally, MySQL can be well managed as long as SQL statements are supported. Shell has limited support for MySQL, and two common direct operations are used.

1) execute the command directly through the "-e" option on the command line.
Format: mysql-uusername-ppassword-e "SQL statement"
Example: mysql-u root-p-e "SELECT Name FROM Country WHERE Name LIKE 'au % '; select count (*) FROM City"
Note: This method can be used when the number of statements is small.

2) SQL statements
Format: mysql-uusername-ppassword <SQL statement 1,
SQL statement 2,
SQL statement 3,
.
.
.
EOF
Note: <example: mysql-uuser-ppwd <EOF
Create database members;
Use members;
Create table admin
(
AdminID int (10) not null AUTO_INCREMENT,
Aname varchar (16) not null,
Aloginame varchar (64) not null,
Aloginpwd varchar (64) not null,
Primary key (adminID)
);
EOF
3) These two methods can be used in a mix in Shell scripts.

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.