* 建表语句
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)';