200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > mysql 添加 删除索引(index) alter table 修改字段 修改列

mysql 添加 删除索引(index) alter table 修改字段 修改列

时间:2022-03-27 22:57:17

相关推荐

mysql 添加 删除索引(index) alter table 修改字段 修改列

* 建表语句

CREATE TABLE `config` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(255) NOT NULL COMMENT '配置项',`value` varchar(255) NOT NULL COMMENT '配置值',PRIMARY KEY (`id`),UNIQUE KEY `uniq_config_name` (`name`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

* 添加索引

alter table `config` add index idx_config_name(`name`);

* 删除索引

alter table `config` drop index idx_config_name;

* explain 查看是否使用到了索引

insert into config(name, value, info) values('SMS_ENABLED', '0', '0表示禁用发短信功能, 1表示启用发短信功能');

explain select * from config where name='SMS_ENABLED';

+------+-------------+--------+-------+----------------------------------+------------------+---------+-------+------+-------+

| id | select_type | table | type | possible_keys| key | key_len | ref | rows | Extra |

+------+-------------+--------+-------+----------------------------------+------------------+---------+-------+------+-------+

| 1 | SIMPLE | config | const | uniq_config_name,idx_config_name | uniq_config_name | 194 | const | 1 | |

+------+-------------+--------+-------+----------------------------------+------------------+---------+-------+------+-------+

* 查看mysql版本号

> select version();

+-----------------+

| version() |

+-----------------+

| 10.1.34-MariaDB |

+-----------------+

* 修改某个字段

alter table `rules` change `mobile` `mobile` varchar(128) DEFAULT NULL COMMENT '告警通知手机号码';

alter table easy_eyes.warn modify column request_time int(11) not null comment '请求时长(ms)';

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。