show slave status \G into outfile '/tmp/slavestatus.txt';
Is it possible to write to outfile with the mysql command "show slave status;"?
I have over 20 servers, and I'm writing a bash script to check the replication on all of them. I need to output all of the data into one file on my local server.
开发者_运维技巧This is what I have so far, but I can't figure out how to pipe the data into a file I can run regular expressions on.
#!/bin/bash
for ((server=8100; server <= 8121; server++)); do
ssh pos$server <<-ENDEXP
mysql -u root -p12345 pos_master_prod
show slave status \G
\q
ENDEXP
done
I had the same requirements as you have and ended up using tee. Basically it´s @Chandranshu setup, but using tee to pipe data into a file.
mysql -u root -p'rootpw' pos_master_prod 'show slave status \G' | tee slavestatus.log
Tee was installed by default on my ubuntu boxes, otherwise you can ofcourse get it from a repository like apt-get or yum.
The normal way to run a mysql query from the command prompt is to use the -e option. Hence this would work:
ssh pos$server "mysql -u root -p12345 pos_master_prod -e 'show slave status \G'" >> output.log
UPDATE: About the "into outfile" part, it is not allowed in the syntax. Trying "show slave status into outfile 'xxx'" on the mysql prompt will result in the following error: ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'into outfile "xxx"' at line 1
精彩评论