### 源数据库信息
db_url_source="-h111.111.111.111 -uuser_name -ppasspord"
db_name_source="db_name_source"
### 目录数据库信息
db_url_target="-h111.111.111.111 -uuser_name -ppasspord"
db_name_target="db_name_target"
### 备份文件
db_bak_file="db_bak_${db_name_source}.sql"
db_bak_fix_file="db_bak_${db_name_source}_fix.sql"
# 备份数据库
mysqldump ${db_url_source} --routines ${db_name_source} > ${db_bak_file}
# 修复视图、函数的权限
grep DEFINER ${db_bak_file}|head
sed 's/`userb`/`user_name`/g' ${db_bak_file} > ${db_bak_fix_file}
sed -i 's/`usera`/`user_name`/g' ${db_bak_fix_file}
sed -i 's/`root`/`user_name`/g' ${db_bak_fix_file}
# 还原数据库
mysql ${db_url_target} ${db_name_target} < ${db_bak_fix_file}