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 a database using mysqldump

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to back up the database using mysqldump, the contents of the articles are carefully selected and edited by the author, with a certain pertinence, the reference significance for you is still relatively great, the following with the author to understand how to backup the database using mysqldump.

MySQL single database backup:

Mysqldump-force-opt-single-transaction-lock-tables=false-skip-events-user=root-password=xxxx-routines-databases testdb > singledb.sql

MySQL all database backups:

Mysqldump-force-opt-single-transaction-lock-tables=false-skip-events-user=root-password=xxxx-routines-all-databases > all_databases.sql

MySQL database restore:

Mysql-u root-predhat dbname

< /mnt/dbname.sql MySQL数据库备份的Shell脚本: # mkdir /backups/db_backup/ # vi /backups/mysqlbackup.sh #!/bin/bash export path2=/backups/db_backup date1=`date +%y%m%d_%H%M%S` /usr/bin/find /backups/db_backup/* -type d -mtime +30 -exec rm -r {} \; 2>

/ dev/null

Cd $path2/

Mkdir $date1

USER= "root"

PASSWORD= "redhat123"

OUTPUTDIR= "$path2/$date1"

MYSQLDUMP= "/ usr/bin/mysqldump"

MYSQL= "/ usr/bin/mysql"

HOST= "localhost"

Databases= `$ MYSQL-user=$USER-password=$PASSWORD-host=$HOST\

-e "SHOW DATABASES;" | tr-d "|" | grep-v Database`

Echo "`for db in $databases; do

Echo $db

If ["$db" = "performance_schema"]; then

$MYSQLDUMP-force-opt-single-transaction-lock-tables=false-skip-events-user=$USER-password=$PASSWORD-host=$HOST-routines\

-- databases $db | gzip > "$OUTPUTDIR/$db.gz"

Else

$MYSQLDUMP-force-opt-single-transaction-lock-tables=false-events-user=$USER-password=$PASSWORD-host=$HOST-routines\

-- databases $db | gzip > "$OUTPUTDIR/$db.gz"

Fi

Done `"

: wq

Configure scheduling in crontab:

# The script will run every night at 12 A.M

# crontab-e

0 * / backups/mysqlbackup.sh > / dev/null

After reading the above about how to back up the database using mysqldump, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.

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