Do not log in to the database to execute MySQL command

Source: Internet
Author: User

1. Through the Echo implementation (this is more common)

echo "show databases;" | Mysql-uroot-pqwe123-s/data/3307/mysql.sock

Tip: This method is suitable for cases where there are fewer single-line strings.


2. Through the MYSQL-E parameter realization

Mysql-u root-pqwe123-s/data1/3307/mysql.sock-e "show databases;"


3. Implemented by CAT (not much for this method)

Cat |mysql-uroot-pqwe123-s/data/3307/mysql.sock << EOF

show databases;

Eof

Tip: This method is suitable for multi-line string comparisons.


Special Production Scenario Applications:

Example one: MySQL automatic batch production of master-slave synchronization required statements.

Cat |mysql-uroot-pqwe123-s/data/3307/mysql.sock<< EOF

Change MASTER to

Master_host= ' 10.0.0.16 ',

master_port=3306,

Master_user= ' Jie ',

Master_password= ' qwe123 ',

Master_log_file= ' mysql-bin.000025 '

master_log_pos=4269;

Eof

Tip: Pay more attention to the entire statement, not the contents of the cat.

Example two: "Needle in a haystack" in MySQL thread

Usually log in to the database show Processlist, and found that the results are often very long, find their own to see the more difficult, and


And

SQL display is not complete. If the show full processlist is executed directly then the N-screen is rolled out instantaneously. Find a problem.

SQL statements are very difficult.

Now, I recommend the following statement to you.

Mysql-uroot-pqwe123-e "show full processlist;" | Grep-v Sleep

This command is useful for filtering the full contents of the currently executing SQL statement. You can also add iconv and other Chinese transcoding in the back,

Filter what you want based on your needs.


Do not log in to the database to execute MySQL command

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.