mysql 修改数据库名

想要更该数据库名字,使用rename jdbc  to  jdbc1; 发现有错误,不行!

*******************************************************************************************

MariaDB [(none)]> rename jdbc to jdbc1;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'jdb
c to jdbc1' at line 1

*******************************************************************************************

MariaDB[(none)]> rename jdbc jdbc1;
错误1064(42000):你有一个错误在您的SQL语法;检查手册
对应您的服务器版本的权利MariaDB语法使用“jdb附近
c jdbc1”在1行

于是google一下,发现一种方法:

首先新建一个数据库,然后再把原来数据库里的表转移到新建的数据库中,这样就ok了。

*******************************************************************************************

MariaDB [(none)]> create database jdbc1;
Query OK, 1 row affected (0.00 sec)

*******************************************************************************************

然后转移所有表

rename table  [原数据库].[ 表] to  [员数据库].[ 表];

注意: [原数据库].[ 表] 中间有个点

*******************************************************************************************

MariaDB [jdbc]> rename table jdbc.article to jdbc1.article;
Query OK, 0 rows affected (0.13 sec)


MariaDB [jdbc]> rename table jdbc.employee to jdbc1.employee;
Query OK, 0 rows affected (0.11 sec)


MariaDB [jdbc]> rename table jdbc.person to jdbc1.person;
Query OK, 0 rows affected (0.13 sec)

................

MariaDB [(none)]> use jdbc1;
Database changed
MariaDB [jdbc]> show tables;
+----------------+
| Tables_in_jdbc |
+----------------+
| article        |
| employee       |
| person         |
| student        |
| student1       |
| userlist       |
| users          |
+----------------+
7 rows in set (0.00 sec)


*******************************************************************************************

转移成功了,但总感觉这种办法不是太好,很麻烦~~

打完收工~

猜你喜欢

转载自blog.csdn.net/liqimo1799/article/details/8941748