-- 设置字符集为utf8
set GLOBAL character_set_server='utf8'
-- 设置变量等于某个值
set @d=11
select @d -- 此处可查到d的值为11
集合(SET)mysql>create table jihe(f1 set('f','m'))
Query OK, 0 rows affected (0.11 sec)
mysql>desc jihe
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| f1| set('f','m') | YES | | NULL| |
+-------+--------------+------+-----+---------+-------+
可以插入值 "f" "m"
mysql>insert into jihe values("f")
Query OK, 1 row affected (0.56 sec)
mysql>insert into jihe values("m")
Query OK, 1 row affected (0.19 sec)
可以按照序号输入 注意序号为 1 2 4 8 16 32 ....
mysql>insert into jihe values("1")
Query OK, 1 row affected (0.11 sec)
mysql>insert into jihe values("2")
Query OK, 1 row affected (0.11 sec)
所以如果是3那插入的值为 第一个和第二个
mysql>insert into jihe values("3")
Query OK, 1 row affected (0.17 sec)
+-------+
| f1|
+-------+
| f |
| m |
| f |
| m |
| f,m |
+-------+
其他字母不能插入
mysql>insert into jihe values("q")
ERROR 1265 (01000): Data truncated for column 'f1' at row 1
插入空
mysql>insert into jihe values("0")
Query OK, 1 row affected (0.11 sec)
超出序号之和不能插入
mysql>insert into jihe values("4")
ERROR 1265 (01000): Data truncated for column 'f1' at row 1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)