Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to back up mysql database regularly

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to back up mysql database regularly". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to back up mysql database regularly".

Procedure:

1. Put the script in any location, which is not easy to be deleted by mistake.

2. Scheduled tasks. The script is executed once a week as follows:

#! bin/bash

Backuppath=/data/mysql/backupdate=$ (date +% Y%m%d%H%M) SQLuser=rootSQLpwd=passwordmysqldump=/usr/local/mysql/bin/mysqldumpmysql=/usr/local/mysql/bin/mysqlHIS_Date= `date-d $(date-d "- 30 day" +% Y%m%d) +% s` # take the timestamp Sql_Date= `date-d $(date-d "- 7 day" +% Y%m%d) +% s` # from 30 days ago

# enter the mysql database and clear the zabbix historical data

$mysql-u$SQLuser-p$SQLpwd-e "use zabbix; delete from history WHERE 'clock'

< $Sql_Date; delete from history_uint WHERE 'clock' < $Sql_Date; delete from history_str WHERE 'clock' < $Sql_Date; delete from history_text WHERE 'clock' < $Sql_Date; delete from history_log WHERE 'clock' < $Sql_Date; exit " #建立备份目录 if [ ! -e $backuppath ];then mkdir -p $backuppathfi #开始备份zabbix库 $mysqldump -u$SQLuser -p$SQLpwd zabbix >

$backuppath/zabbix$date.sql

# Delete backup data from 1 month ago

Find / data/mysql/backup-mtime + 30-type f-name\ zabbix*.sql-exec rm-f {}\

If the historical data in the database is too large, you can consider losing the historical data by truncate.

$mysql-u$SQLuser-p$SQLpwd-e "use zabbix; truncate table history; truncate table history_log; truncate table history_uint; truncate table history_str; truncate table history_text Exit "Thank you for reading, the above is the content of" how to back up the mysql database regularly ". After the study of this article, I believe you have a deeper understanding of the problem of how to back up the mysql database regularly, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report