mysql rename
时间: 2023-11-05 19:59:50 浏览: 136
rename
在MySQL中,可以使用RENAME TABLE语句或ALTER TABLE语句来重命名表。具体语法如下:
1. RENAME TABLE语法:RENAME TABLE tbl_name TO new_tbl_name [, tbl_name2 TO new_tbl_name2] ...
2. ALTER TABLE语法:ALTER TABLE old_table RENAME new_table;
下面是一个具体的示例:
```
mysql> show tables;
------------------
| Tables_in_testdb |
------------------
| tb1 |
| tb2 |
------------------
2 rows in set (0.00 sec)
mysql> rename table tb1 to new_tb1;
Query OK, 0 rows affected (0.03 sec)
mysql> alter table tb2 rename new_tb2;
Query OK, 0 rows affected (0.04 sec)
mysql> show tables;
------------------
| Tables_in_testdb |
------------------
| new_tb1 |
| new_tb2 |
------------------
2 rows in set (0.00 sec)
```
另外,如果你遇到类似的错误,你可以尝试添加一些反引号(``)来解决,例如:
```
RENAME TABLE `os`.`table_name` TO `os-cs`.`table_name`;
ALTER TABLE `os`.`table_name` rename `os-cs`.`table_name`;
```
阅读全文