Shell

推荐列表 站点导航

当前位置:首页 > 脚本编程 > Shell >

mysql纯文本格式备份的shell脚本

来源:互联网  作者:网友投稿  发布时间:2021-01-07 11:49
本文分享一段shell脚本,用于实现mysql的纯文本格式备份,有需要的朋友,可以作个参考。...

所谓的mysql纯文本格式数据,是在数据表中没有insert into这样的查询sql语句的存在,而只有类似如下:
 

'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
 

的纯数据结构。
此种备份方式,可以节约很多存储空间。
不过此种备份的难度也要比传统的mysqldump要大。

本文以mysql数据库中的test数据库为例子,用shell脚本实现这种备份。

用到的shell 脚本,代码如下:
 

复制代码 代码示例:

#!/bin/bash 
tables=`sudo /Applications/XAMPP/xamppfiles/bin/mysql -uroot -p test -e 'show tables'` 
echo $tables 
for i in $tables 
do 
    if [ $i = 'Tables_in_test' ]  
    then 
        continue     
    fi 
sudo /Applications/XAMPP/xamppfiles/bin/mysqldump -uroot -l -T /tmp/ test $i --fields-enclosed=\" --fields-terminated-by=, 
done 
执行脚本,即可把mysql数据和sql文件全部备份到/tmp/目录。

以下是恢复备份的shell 脚本,代码如下:
#!/bin/bash 
sqlList=`ls /tmp/*.sql` 
txtList=`ls /tmp/*.txt` 
for i in $sqlList 
do 
    sudo /Applications/XAMPP/xamppfiles/bin/mysql -uroot test < $i 
done 
for i in $txtList 
do 
    sudo /Applications/XAMPP/xamppfiles/bin/mysqlimport --user=root test --fields-enclosed-by=\" --fields-terminated-by=, $i 
done 
 

注意:
恢复时要把sql文件和txt分别导入进来,先把所有的sql文件导入进来,然后再导入数据文件txt即可。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/shell/11782.shtml

相关文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

mysql纯文本格式备份的shell脚本

2021-01-07 编辑:网友投稿

所谓的mysql纯文本格式数据,是在数据表中没有insert into这样的查询sql语句的存在,而只有类似如下:
 

'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
 

的纯数据结构。
此种备份方式,可以节约很多存储空间。
不过此种备份的难度也要比传统的mysqldump要大。

本文以mysql数据库中的test数据库为例子,用shell脚本实现这种备份。

用到的shell 脚本,代码如下:
 

复制代码 代码示例:

#!/bin/bash 
tables=`sudo /Applications/XAMPP/xamppfiles/bin/mysql -uroot -p test -e 'show tables'` 
echo $tables 
for i in $tables 
do 
    if [ $i = 'Tables_in_test' ]  
    then 
        continue     
    fi 
sudo /Applications/XAMPP/xamppfiles/bin/mysqldump -uroot -l -T /tmp/ test $i --fields-enclosed=\" --fields-terminated-by=, 
done 
执行脚本,即可把mysql数据和sql文件全部备份到/tmp/目录。

以下是恢复备份的shell 脚本,代码如下:
#!/bin/bash 
sqlList=`ls /tmp/*.sql` 
txtList=`ls /tmp/*.txt` 
for i in $sqlList 
do 
    sudo /Applications/XAMPP/xamppfiles/bin/mysql -uroot test < $i 
done 
for i in $txtList 
do 
    sudo /Applications/XAMPP/xamppfiles/bin/mysqlimport --user=root test --fields-enclosed-by=\" --fields-terminated-by=, $i 
done 
 

注意:
恢复时要把sql文件和txt分别导入进来,先把所有的sql文件导入进来,然后再导入数据文件txt即可。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/shell/11782.shtml

相关文章

风云图片

推荐阅读

返回Shell频道首页