Use Shell scripts to implement remote MySQL automatic Query

Source: Internet
Author: User

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

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.