Shell (BASH)-MySQL database operations

Source: Internet
Author: User
Tags mysql commands

Three methods of using shell to operate MySQL Databases

Method 1:
#! /Bin/sh
Mysql-uroot <EOF
[SQL statement]
EOF
The commands between EOF and eof are all MySQL commands. EOF is only a token and can be replaced by other characters.

Method 2:
#! /Bin/sh
SQL = "SQL statement"
Echo $ SQL> "1. SQL"
Mysql-uroot <"1. SQL"
This is not a very good method. Write the statement into the SQL text before importing it into the database.

Method 3:
#! /Bin/sh
Mysql-u root-P password-e "use MySQL; select * from user (SQL statement )";
Exit 0;
Use the command line to directly write MySQL commands to the database.

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.