修改数据库名的一种方法

Updated on in Linux系列 with 0 views and 0 comments

一种快速安全的改名方法

#!/bin/bash
# 假设将cuijianzhe数据库名改为solo
# MyISAM直接更改数据库目录下的文件即可
password='12345678'
mysql -uroot -p$password -e 'create database if not exists solo'
 
list_table=$(mysql -uroot -p$password -Nse "select table_name from information_schema.TABLES where TABLE_SCHEMA='cuijianzhe'")
 
for table in $list_table
do
    mysql -uroot -p$password -e "rename table cuijianzhe.$table to solo.$table"
done

这里用到了 rename table,改表名的命令,但是如果新表名后面加数据库名,就会将老数据库的表移动到新的数据库,所以,这种方法即安全,又快速。


标题:修改数据库名的一种方法
作者:cuijianzhe
地址:https://cuijianzhe.github.io/articles/2020/08/23/1598183218602.html

到头来 我们记住的 不是敌人的攻击 而是朋友的沉默 ---马丁·路德·金