教程集 www.jiaochengji.com
教程集 >  数据库  >  mysql  >  正文 更改MySQL数据库名实例代码

更改MySQL数据库名实例代码

发布时间:2016-03-29   编辑:jiaochengji.com
分享一例更改mysql数据库的数据库名的代码,有需要的朋友参考下。

修改数据库名称的详细步骤:
 

复制代码 代码示例:

mysql> use dinghao;
mysql> select * from t1;
+——+———–+
| id | name |
+——+———–+
| 1 | 刘德华 |
+——+———–+
1 row in set (0.00 sec)
mysql> show create table t1;

+——-+————————————————————————————————————————-+

| Table | Create Table |

+——-+————————————————————————————————————————-+

| t1 | CREATE TABLE `t1` (

`id` int(11) DEFAULT NULL,

`name` varchar(20) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

+——-+————————————————————————————————————————-+

1 row in set (0.00 sec)

mysql> flush tables;

Query OK, 0 rows affected (0.00 sec)

mysql> flush logs;

Query OK, 0 rows affected (0.00 sec)

mysql> show processlist; #查看有没有其他进程连接,要保证没有其他程序操作数据库。

+—-+——+———–+———+———+——-+——-+——————+

| Id | User | Host | db | Command | Time | State | Info |

+—-+——+———–+———+———+——-+——-+——————+

| 17 | root | localhost | dinghao | Query | 0 | NULL | show processlist |

+—-+——+———–+———+———+——-+——-+——————+

1 rows in set (0.00 sec)

mysql> alter table t1 engine=MyISAM;

Query OK, 1 row affected (0.01 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> exit

[root@mysqludf var]# mv dinghao aaa;

mysql> use aaa;

Database changed

mysql> alter table t1 engine=INNODB;

Query OK, 1 row affected (0.00 sec)

Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from t1;

+——+———–+

| id | name |

+——+———–+

| 1 | 刘德华 |

+——+———–+

1 row in set (0.00 sec)

注意,在改名之前必须现转换存储引擎,否则会报错,想换的这个名称就换不成了,只能换另外一个名称了。

您可能感兴趣的文章:
linux下指定数据库服务器主从同步的实例
Linux下指定数据库数据配置主主同步的实例
mysql导出数据库多种方法
mysql导入sql文件 mysql远程登录
mysql更新字段中部分内容的sql语句
快速修改Mysql数据库名的五种方法
mysql命令行操作大全 mysql命令行操作总结
linux下mysql添加用户、删除用户、授权、修改密码
查看mysql编码方式 mysql数据库编码查看方法
mysql添加、删除用户及授权、修改密码实例详解

关键词: 数据库名字   
[关闭]
~ ~