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