Home > Database > Mysql Tutorial > TIPS:MySQL 改库名操作_MySQL

TIPS:MySQL 改库名操作_MySQL

WBOY
Release: 2016-06-01 13:06:13
Original
919 people have browsed it

作者:吴炳锡 来源:http://www.mysqlsupport.cn/ 联系方式: wubingxi#163.com 转载请注明作/译者和出处,并且不能用于商业用途,违者必究.

MySQL在5.1引入了一个rename database操作,但在MySQL5.1.23后又不支持这个命令。可以说是一个实验性的功能,没有在生产中支持过(mysql-5.1 release在mysql-5.1.30),那么生产中我们有时为了追求完美需要改一下库名。怎么操作呢?

这里提供一个变通的方法。

1. 创建出新库名:

mysql>create database db_v2;
Copy after login
  1. 生成rename语句,从olddb里迁移,我这里olddb里sbtest;
mysql>select concat("rename table ",table_schema,".",table_name," to db_v2.",table_name,";") into outfile '/tmp/rename_to_db_v2.sql' from information_schema.tables where table_schema='sbtest';
Copy after login

3.执行生成的sql

mysql>source /tmp/rename_to_db_v2.sql
Copy after login

就这么简单可以搞定了。Good luck!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template