Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the practical shell scripts in MYSQL

Shulou Source: shulou.com Published: 2022-05-31 15:56:24 10月26日 Update

Editor to share with you what are the practical shell scripts in MYSQL, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

To extract the error information of mysql and call the police, you can follow these steps:

# # variable setting # #

Mark= `date +% Y% m% d% H% M`

Error_file=/data/mysql/data/error.log

Bak_file=/tmp/error_bak.log

Report_file=/tmp/error_rport.log

# create one without error.bak, extract error field information to ${report_file (use > here to assume later email failed and need to retain error information); read ${error_file} and append ${bak_file} (equivalent to backup); clear ${error_file}

[!-f ${bak_file}] & & touch ${bak_file}

[!-f ${report_file}] & & touch ${report_file}

Cat ${error_file} | grep "\ [ERROR\]" > > ${report_file} & & cat ${error_file} > > ${bak_file} & & > ${error_file}

# check the size of ${report_file. If it is greater than 0 (indicating error information), send an email, and then clear ${report_file}.

Logsize= `du-b ${report_file} | awk'{print $1}'`

[$logsize-gt 0] & & / usr/local/bin/sendEmail... & & > ${report_file}

The above can also be simplified to [- s ${logfile}] & & / usr/local/bin/sendEmail. & & > ${report_file}

To extract the slow log of Mysql in real time and give an alarm, you can follow the steps below:

# # variable setting # #

Mark= `date +% Y% m% d% H% M`

Process=/tmp/showprocesslist.log

Slow=/tmp/slow.log

# # output processlis to ${process}. Extract the query information of time > 5 to ${slow}. Use > > to assume that the subsequent email failed, and you need to retain the slow information.

/ usr/local/mysql/bin/mysql-usystem-palitiaoling.compose 123'-e "show full processlist;" | sed's /\\ t\ |\ n / / g'> ${process}

Cat ${process} | awk'($6 > = 5) & & ($660) & & ($6)

Tags: Information mail variables backups articles alarms scripts reality content steps checks not much size most fields real-time logs more knowledge industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei macOS OPPO Reno Linux