博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 数据库修改名字
阅读量:5925 次
发布时间:2019-06-19

本文共 3828 字,大约阅读时间需要 12 分钟。

通过information_schema信息修改rename database的目的

  • mysql 没有rename database 命令,只能变相修改表到目标库里的表来实现:
  • 拼接reanme tables的执行语句
root@localhost [information_schema]>select concat('rename table sysbench_testdata.',table_name,' to wenyz.',table_name,';') from information_schema.tables where table_sschema='sysbench_testdata';+----------------------------------------------------------------------------------+| concat('rename table sysbench_testdata.',table_name,' to wenyz.',table_name,';') |+----------------------------------------------------------------------------------+| rename table sysbench_testdata.sbtest10 to wenyz.sbtest10;                       || rename table sysbench_testdata.sbtest2 to wenyz.sbtest2;                         || rename table sysbench_testdata.sbtest3 to wenyz.sbtest3;                         || rename table sysbench_testdata.sbtest4 to wenyz.sbtest4;                         || rename table sysbench_testdata.sbtest5 to wenyz.sbtest5;                         || rename table sysbench_testdata.sbtest6 to wenyz.sbtest6;                         || rename table sysbench_testdata.sbtest7 to wenyz.sbtest7;                         || rename table sysbench_testdata.sbtest8 to wenyz.sbtest8;                         || rename table sysbench_testdata.sbtest9 to wenyz.sbtest9;                         |+----------------------------------------------------------------------------------+9 rows in set (0.00 sec)
  • 改进:希望拼接语句直接导出到指定文件,再导入批量执行
root@localhost [information_schema]>select concat('rename table sysbench_testdata.',table_name,' to wenyz.',table_name,';') from information_schema.tables where table_schema='sysbench_testdata' into outfile '/tmp/1.sql' ;ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statementroot@localhost [information_schema]>show variables like '%secure%';+--------------------------+-------+| Variable_name            | Value |+--------------------------+-------+| require_secure_transport | OFF   || secure_auth              | ON    || secure_file_priv         | NULL  |+--------------------------+-------+3 rows in set (0.01 sec)root@localhost [information_schema]>set global secure_file_priv='/tmp';ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variableroot@localhost [information_schema]>shutdown;#vi /3506/my.cnf //增加以下参数:secure_file_priv=/tmp#/usr/local/mysql57/bin/mysqld --defaults-file=/3506/my3506.cnf & //再次启动:[2] 22558[root@db210_14:04:44 /tmp]  #mysql --login-path=p3506root@localhost [(none)]>select concat('rename table sysbench_testdata.',table_name,' to wenyz.',table_name,';') from information_schema.tables where table_schema='sysbench_testdata' into outfile '/tmp/1.sql' ;Query OK, 9 rows affected (0.00 sec)root@localhost [(none)]>source /tmp/1.sql;ERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...Connection id:    3Current database: *** NONE ***Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.01 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)root@localhost [(none)]>use sysbench_testdata;Database changedroot@localhost [sysbench_testdata]>show tables;Empty set (0.00 sec)root@localhost [sysbench_testdata]>use wenyz;Database changedroot@localhost [wenyz]>show tables;+-----------------+| Tables_in_wenyz |+-----------------+| sbtest1         || sbtest10        || sbtest2         || sbtest3         || sbtest4         || sbtest5         || sbtest6         || sbtest7         || sbtest8         || sbtest9         || t2              |+-----------------+11 rows in set (0.00 sec)

转载于:https://www.cnblogs.com/2woods/p/9406585.html

你可能感兴趣的文章
放弃winform的窗体吧,改用html作界面,桌面应用程序UI的新的开发方式。
查看>>
学习RUNOOB.COM进度一
查看>>
[iOS]应用内支付(内购)的个人开发过程及坑!
查看>>
3四则运算软件2016011992
查看>>
0408~送给小伙伴的汉堡包
查看>>
HTML5程序开发范例宝典 完整版 (韩旭等著) 中文pdf扫描版
查看>>
maven,gradle本地缓存位置
查看>>
第五十三篇、OC利用AFN上传视频到服务器
查看>>
你周围需要这6种人(文摘)
查看>>
Java精选笔记_JDBC
查看>>
mybatis由浅入深day01_5mybatis开发dao的方法(5.1SqlSession使用范围_5.2原始dao开发方法)...
查看>>
图像柔光效果(SoftGlow)的原理及其实现。
查看>>
Protel中的快捷键使用(网上资源)
查看>>
JS多个对象添加到一个对象中
查看>>
Javascript:阻止浏览器默认右键事件,并显示定制内容
查看>>
[There will be more story......]
查看>>
The SDK platform-tools version ((23)) is too old to check APIs compiled with API 26;
查看>>
《大道至简》读后感
查看>>
缩点(有向图的强连通分量)学习笔记
查看>>
JavaScript对SEO的影响及解决之道
查看>>