当前位置: 首页 > news >正文

mysql 数据库修改名字

通过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 statement
root@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 variable
root@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=p3506
root@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 away
No connection. Trying to reconnect...
Connection id:    3
Current 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 changed
root@localhost [sysbench_testdata]>show tables;
Empty set (0.00 sec)

root@localhost [sysbench_testdata]>use wenyz;
Database changed
root@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

相关文章:

  • 设计模式-简单工厂、工厂方法模式、抽象工厂模式详解
  • 9种数据分析方法
  • 人群估值一般性算法
  • oracle获取过去两年的今天时间
  • SOFATracer 中 Disruptor 实践
  • C#抽象类与接口的区别【转】
  • 区块链时代的拜占庭容错:Tendermint(一)
  • 一致性算法Hash(Consistent Hashing)
  • Java 多线程
  • 微信小程序登录JAVA后台
  • yii2.0 验证码
  • Weakpass
  • MySQL基础知识之DDL操作
  • ubuntu LNMP nginx 隐藏index.php 配置文件
  • saltstack离线安装内部yum源搭建
  • HTTP中的ETag在移动客户端的应用
  • linux安装openssl、swoole等扩展的具体步骤
  • PHP那些事儿
  • Python学习笔记 字符串拼接
  • vue 配置sass、scss全局变量
  • 不上全站https的网站你们就等着被恶心死吧
  • 工程优化暨babel升级小记
  • 构建工具 - 收藏集 - 掘金
  • 浅析微信支付:申请退款、退款回调接口、查询退款
  • 我从编程教室毕业
  • 优化 Vue 项目编译文件大小
  • MyCAT水平分库
  • ​软考-高级-信息系统项目管理师教程 第四版【第14章-项目沟通管理-思维导图】​
  • ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
  • #《AI中文版》V3 第 1 章 概述
  • #includecmath
  • #stm32整理(一)flash读写
  • $forceUpdate()函数
  • (3)nginx 配置(nginx.conf)
  • (AtCoder Beginner Contest 340) -- F - S = 1 -- 题解
  • (ibm)Java 语言的 XPath API
  • (Redis使用系列) SpringBoot 中对应2.0.x版本的Redis配置 一
  • (附源码)springboot 房产中介系统 毕业设计 312341
  • (附源码)springboot优课在线教学系统 毕业设计 081251
  • (区间dp) (经典例题) 石子合并
  • (转)关于pipe()的详细解析
  • .halo勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
  • .java 9 找不到符号_java找不到符号
  • .net开源工作流引擎ccflow表单数据返回值Pop分组模式和表格模式对比
  • [<死锁专题>]
  • [2015][note]基于薄向列液晶层的可调谐THz fishnet超材料快速开关——
  • [ARC066F]Contest with Drinks Hard
  • [dts]Device Tree机制
  • [ERROR] Plugin 'InnoDB' init function returned error
  • [iOS]中字体样式设置 API
  • [leetcode]Symmetric Tree
  • [NEWS] J2SE5.0来了
  • [NOIP2015] 运输计划
  • [noip模拟]计蒜姬BFS
  • [Redis实战]分布式锁-redission