首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Mycat 运行与基础操作8

Mycat 运行与基础操作8

作者头像
franket
发布于 2021-12-03 20:21:17
发布于 2021-12-03 20:21:17
3920
举报
文章被收录于专栏:技术杂记技术杂记

修改表结构

添加列

代码语言:javascript
复制
mysql> desc catworld4;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(30) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> alter table catworld4 add test int;
Query OK, 0 rows affected (4.22 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc catworld4;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(30) | YES  |     | NULL    |       |
| test  | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> 

修改列类型

代码语言:javascript
复制
mysql> alter table catworld4 modify test varchar(10);
Query OK, 10 rows affected (0.91 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> desc catworld4;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| name  | varchar(30) | YES  |     | NULL    |       |
| test  | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.04 sec)

mysql>

添加索引

代码语言:javascript
复制
mysql> create index idx_test on catworld4(test);
Query OK, 0 rows affected (6.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table catworld4\G
*************************** 1. row ***************************
       Table: catworld4
Create Table: CREATE TABLE `catworld4` (
  `id` int(11) NOT NULL,
  `name` varchar(30) DEFAULT NULL,
  `test` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_test` (`test`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.01 sec)

mysql> 

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

目录
  • 修改表结构
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档