The following script is a simple command used to execute remote database queries. I believe everyone can understand it. This is for some brothers who need to automatically check the database or execute certain statements every day, it is very helpful. You only need to modify it a little.
Copy codeThe Code is as follows:
#! /Bin/sh
HOST = 192.168.5.40
USER = abc
Passes = 123456
QUERY = 'mysql-h $ HOST-u $ USER-p $ PASS <EOF
Use testdb;
Select * from person where name = 'liming ';
Exit
EOF'
Echo $ QUERY
For example, if you change this script to a script used to safely delete mysql 2 process logs, the binary log of the Mysql master-slave synchronization database is usually large and it is not safe to manually delete files.
Copy codeThe Code is as follows:
#! /Bin/sh
Host = 192.168.5.30
User = abc
PW = 123456
MSG = 'mysql-h $ Host-u $ User-p $ PW <eof <font = "">
Show master status;
Exit
EOF'
LOG = 'echo $ MSG | awk' {print $5 }''
Mysql-h $ Host-u $ User-p $ PW <FOE
Purge master logs to "$ LOG ";
Exit
FOE