#!/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