大家好,又见面了,我是你们的朋友全栈君。
改变表名 mysql> ALTER TABLE `原表名` RENAME TO `新表名`;
改库名 可以把原库倒出来然后恢复到新库里 show variables like ‘table_type’; +—————+——–+ | Variable_name | Value | +—————+——–+ | table_type | MyISAM | +—————+——–+ 1 row in set (0.00 sec) 如果是MyISAM的话,只要修改DATA目录下面的那个库名的文件夹的名字就OK了。 找数据的路径: show variables like ‘data%’; +—————+—————–+ | Variable_name | Value | +—————+—————–+ | datadir | /var/lib/mysql/ | +—————+—————–+ 1 row in set (0.00 sec)
如果是INNODB的话,其实是无法修改库名的. 一种方法是比较保守的,直接把老库的内容mysqldump到新库里面。 还有一种类似上面方法,先把表的存储引擎修改为MyISAM,然后再改库目录的名字,最后再把表的存储引擎改为INNODB。 其实还有最后一种方法,如下,最后一种方法还是比较好些,速度也很快。
假设源库名是’ceshi1’,目标库名是’ceshi2’ 首先创建目标库 create database ceshi1; 获取所有源库的表名 use information_schema; select table_name from TABLES where TABLE_SCHEMA=ceshi1; 然后按照以下命令一个个修改 rename table ceshi1.[tablename] to ceshi1.[tablename]; 一个个执行下来之后表就转到新的库里面了.
手册摘录: This statement was added in MySQL 5.1.7 but was found to be dangerous and was removed in MySQL 5.1.23. It was intended to enable upgrading pre-5.1 databases to use the encoding implemented in 5.1 for mapping database names to database directory names (see Section 8.2.3, “Mapping of Identifiers to File Names”). However, use of this statement could result in loss of database contents, which is why it was removed. Do not use RENAME DATABASE in earlier versions in which it is present.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139744.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有