Summary of executing mysql commands without logging on to the database

Source: Internet
Author: User
Tags mysql commands

 

Summary of executing mysql commands without logging on to the database

(This article is suitable for readers who have some experience in mysql databases)

######################################## #################

 

 

Example 1. Implement through echo (this is common)

Echo "show databases;" | mysql-uroot-p 'oldboy '-S/data/3308/mysql. sock

Tip: This method is suitable for the case where there are few single-line strings.

Protocol 2. Implementation through cat (this method is rarely used)

Cat | mysql-uroot-p 'oldboy '-S/data/3308/mysql. sock <EOF

Show databases;

EOF

Tip: This method is suitable when there are many strings in multiple lines.

3. Using mysql-e parameters

Mysql-u root-p 'oldboy '-S/data1/3307/mysql. sock-e "show databases ;"

█ Special production scenarios:

Example 1: mysql automatically creates the statements required for master-slave synchronization in batches.

Cat | mysql-uroot-p 'oldboy '-S/data/3308/mysql. sock <EOF

CHANGE MASTER

MASTER_HOST = '10. 0.0.16 ',

MASTER_PORT = 3306,

MASTER_USER = 'oldboyrep ',

MASTER_PASSWORD = 'oldboyrep ',

MASTER_LOG_FILE = 'mysql-bin.000025'

MASTER_LOG_POS = 4269;

EOF

Tip: pay more attention to the writing of the entire statement, rather than the content in cat.

Example 2: "haystack" in the mysql thread"

Usually log on to the database show processlist; and find that the results are often too long, it is difficult to find what you want to see, and,

SQL display is incomplete. If you run show full processlist directly, the N screen is rolled instantly. Find the problematic

SQL statements are very difficult.

Now, the old man recommends the following statement.

Mysql-u root-p 'oldboy '-S/data1/3307/mysql. sock-e "show full processlist;" | grep-v Sleep

This command is useful for filtering the complete content of the currently executed SQL statement. I wonder if you can understand it. You can also add iconv and other Chinese transcodes later,

Filter the desired content as needed. This command has been tried and tested repeatedly.

 

 

This article is from the "old boy's linux blog" blog

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.