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