foundwant

第一种:

RENAME database olddbname TO newdbname

这种方法官方不推荐,因为可能会造成数据丢失,所以不建议使用;

 

另一种:自己写脚本实现

 1 #!/bin/bash
 2 mysql -uroot -e "create database if not exists db_ym_account"
 3 list_table=$(mysql -uroot -Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA=\'foundwant\'")
 4 
 5 echo $list_table
 6 for tab in $list_table
 7 do
 8     echo "$tab"
 9     mysql -uroot -e "rename table foundwant.$tab to db_ym_account.$tab"
10 done

上面这里,我们想把db中foundwant的库名改成db_ym_account;

第1行,创建db_ym_account库;

第3行,把库foundwant中的表记录下来;

第9行,我们使用rename来操作table,这种方式就能把老库中表中的数据转移到新库表中去;

 

分类:

技术点:

相关文章:

  • 2021-11-19
  • 2021-12-29
  • 2022-01-13
  • 2021-11-19
  • 2021-11-19
  • 2021-08-01
  • 2021-11-19
猜你喜欢
  • 2021-12-20
  • 2021-11-19
  • 2021-11-21
  • 2021-12-24
  • 2022-01-19
  • 2021-11-19
  • 2021-11-19
相关资源
相似解决方案