mysql 資料庫修改名字

來源:互聯網
上載者:User

標籤:0 rows   修改   serve   secure   tables   var   concat   cut   test   

通過information_schema資訊修改rename database的目的
  • mysql 沒有rename database 命令,只能變相修改表到目標庫裡的表來實現:
  • 拼接reanme tables的執行語句
[email protected] [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)
  • 改進:希望拼接語句直接匯出到指定檔案,再匯入批量執行
[email protected] [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[email protected] [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)[email protected] [information_schema]>set global secure_file_priv=‘/tmp‘;ERROR 1238 (HY000): Variable ‘secure_file_priv‘ is a read only variable[email protected] [information_schema]>shutdown;#vi /3506/my.cnf //增加以下參數:secure_file_priv=/tmp#/usr/local/mysql57/bin/mysqld --defaults-file=/3506/my3506.cnf & //再次啟動:[2] 22558[[email protected]_14:04:44 /tmp]  #mysql --login-path=p3506[email protected] [(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)[email protected] [(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)[email protected] [(none)]>use sysbench_testdata;Database changed[email protected] [sysbench_testdata]>show tables;Empty set (0.00 sec)[email protected] [sysbench_testdata]>use wenyz;Database changed[email protected] [wenyz]>show tables;+-----------------+| Tables_in_wenyz |+-----------------+| sbtest1         || sbtest10        || sbtest2         || sbtest3         || sbtest4         || sbtest5         || sbtest6         || sbtest7         || sbtest8         || sbtest9         || t2              |+-----------------+11 rows in set (0.00 sec)

mysql 資料庫修改名字

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.