邯城往事 邯城往事

来自邯郸社畜的呐喊

目录
修改数据库名的一种方法
/  

修改数据库名的一种方法

一种快速安全的改名方法

#!/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://cjzshilong.cn/articles/2020/08/23/1598183280801.html