Security Code: To prevent accidental deletion of the system database, scheduled backup you I more peace of mind!
automating backup databases with shell scripts
First, Introduction
System database (take MySQL5.5 as an example)
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/87/48/wKiom1faI52jq-ihAAAGaW9Asms259.png-wh_500x0-wm_3 -wmp_4-s_437084086.png "title=" 9FD ' Ty5o~gebbozyl_t$h84.png "alt=" Wkiom1fai52jq-ihaaagaw9asms259.png-wh_50 "/>
1. INFORMATION_SCHEMA: information Database, which holds information about all other databases maintained by the MySQL server. In Information_schema, there are a few read-only tables. They are actually views, not basic tables, so you will not be able to see any files associated with them.
2. mysql:MySQL's core database , similar to the master table in SQL Server, is responsible for storing the database user, permission settings, keywords, MySQL's own need to use the control and management information. Can not be deleted, if the MySQL is not very understanding, and do not easily modify the database inside the table information.
3, Performance_schema: Storage engine, mainly used to collect database server performance parameters.
4, test: The installation time to create a test database, and its name, is a complete empty database, no table, can be deleted.
Ii. scripting, automating backup databases (for example, test)
1. Open service
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/87/49/wKiom1faJlmxHq_JAAAEdxGTGXE978.png-wh_500x0-wm_3 -wmp_4-s_3676472631.png "title=" W[f}rp7]$7gcwrh%a~[dnlw.png "alt=" Wkiom1fajlmxhq_jaaaedxgtgxe978.png-wh_50 "/>
2. User authorization
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/87/46/wKioL1faJnzSHXS2AAAFCblPjtk396.png-wh_500x0-wm_3 -wmp_4-s_567182841.png "title=" (h~5ue{k7n$7{wxq_z68) d4.png "alt=" Wkiol1fajnzshxs2aaafcblpjtk396.png-wh_50 "/>
3. Scripting (VIM yy.sh)
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/87/46/wKioL1faJqPQ-vYkAAAR9ZD7kTE236.png-wh_500x0-wm_3 -wmp_4-s_1657854436.png "title=" (Oa_fsnxo$p] (4]kwqv6t.png "alt=" Wkiol1fajqpq-vykaaar9zd7kte236.png-wh_50 "/>
The script is as follows:
#!/bin/bash
#auto Backup
back=/data/backup/' Date +%y%m%d '
Mysqldb=test
mysqlpw=123456
Mysqluser=backup
mysqlcmd=$ (which mysqldump)
If [$UID-ne 0];then
echo "Bixushiyongroot"
Exit
Fi
if [!-D $back];then
Mkdir-p $back
Else
echo "This $back is exit ......."
Fi
$mysqlcmd-u$mysqluser-p$mysqlpw-d $mysqldb > $back/$mysqldb. sql
If [$? -eq 0];then
echo "The backup successful"
Else
echo "Backup failure"
Fi
4. Set execution permissions and execute scripts
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/87/49/wKiom1faJtDSm2dfAAAUIOCOzVs977.png-wh_500x0-wm_3 -wmp_4-s_3280256739.png "title=" 94i7j~ezf] $RE 9yvp{897c0.png "alt=" Wkiom1fajtdsm2dfaaauiocozvs977.png-wh_50 "/>
Three, according to the work needs, set up the planning task (CRONTAB-E)
This article from "A Candle" blog, declined reprint!
Automating backup databases with shell scripts