1.用户权限涉及表:mysql.user,mysql.db,mysql.table_priv,mysql.column_priv
grant SELECT on mall.* TO 'dev'@'192.168.244.%' IDENTIFIED BY '123' WITH GRANT OPTION;
flush privileges;
show grants for 'dev'@'192.168.244.%';
grant select(id,name) on mall.account to 'dev'@'192.168.244.%';
REVOKE SELECT on mall.* from 'dev'@'192.168.244.%';
mysql中角色就是用户
show variables like "%proxy%";
要先把check_proxy_users,mysql_native_password_proxy_users这两个变量设置成true,或者改my.cn
set GLOBAL check_proxy_users =1;
set GLOBAL mysql_native_password_proxy_users = 1;
创建角色
create USER 'dev_role'
把角色赋给用户
grant proxy on 'dev_role' to 'test'
grant proxy on 'dev_role' to 'manage'
如果远程连接,没有权限做这个,执行:
GRANT PROXY ON ''@'' TO 'root'@'%' WITH GRANT OPTION;
类型 | 字节 | 最小值 | 最大值 | |
---|---|---|---|---|
TINYINT | 1 | -128 | 127 | |
0 | 255 | |||
SMALLINT | 2 | -32768 | 32767 | |
0 | 65535 | |||
MEDIUMINT | 3 | -8388608 | 8388607 | |
0 | 16777215 | |||
INT | 4 | -2147483648 | 2147483647 | |
0 | 4294967295 | |||
BIGINT | 8 | -9223372036854775808 | 9223372036854775807 | |
0 | 18446744073709551615 |
未申明时,默认是有符号的,如果为无符号的
下图会出错
create table test_unsigned(a int unsigned, b int unsigned);
insert into test_unsigned values(1, 2);
select b - a from test_unsigned;
select a - b from test_unsigned; --运行出错(a
zerofill 表示当存储的数字长度< N 时,用数字0 填充左边,直至补满长度N
当存储数字的长度超过N 时,按照实际存储的数字显示
create table test_int_n(a int(4) zerofill);
insert into test_int_n values(1);
insert into test_int_n values(123456);
create table test_auto_increment(a int auto_increment primary key); --成功
create table test_auto_increment(a int auto_increment); --失败
insert into test_auto_increment values(NULL); --a为当前最大值自增
insert into test_auto_increment values(0); --a为当前最大值自增
insert into test_auto_increment values(-1); --a为-1
类型 | 说明 | N 的含义 | 是否有字符集 | 最大长度 |
---|---|---|---|---|
CHAR(N) | 定长字符 | 字符 | 是 | 255 |
VARCHAR(N) | 变长字符 | 字符 | 是 | 16384 |
BINARY(N) | 定长二进制字节 | 字节 | 否 | 255 |
VARBINARY(N) | 变长二进制字节 | 字节 | 否 | 16384 |
TINYBLOB(N) | 二进制大对象 | 字节 | 否 | 256 |
BLOB(N) | 二进制大对象 | 字节 | 否 | 16K |
MEDIUMBLOB(N) | 二进制大对象 | 字节 | 否 | 16M |
LONGBLOB(N) | 二进制大对象 | 字节 | 否 | 4G |
TINYTEXT(N) | 大对象 | 字节 | 是 | 256 |
TEXT(N) | 大对象 | 字节 | 是 | 16K |
MEDIUMTEXT(N) | 大对象 | 字节 | 是 | 16M |
LONGTEXT(N) | 大对象 | 字节 | 是 | 4G |
ci是 case insensitive:
general_ci:不支持扩展,准确性相对于Unicode_ci来说要低一点,速度快Unicode_ci
cs为case sensitive
bin:每个字符串用二进制数据编译存储, 区分大小写
日期类型 | 占用空间 | 表示范围 |
---|---|---|
DATETIME | 8 | 1000-01-01 00:00:00 ~ 9999-12-31 23:59:59 |
DATE | 3 | 1000-01-01 ~ 9999-12-31 |
TIMESTAMP | 4 | 1970-01-01 00:00:00UTC ~ 2038-01-19 03:14:07UTC |
YEAR | 1 | YEAR(2):1970-2070, YEAR(4):1901-2155 |
TIME | 3 | -838:59:59 ~ 838:59:59 |
1.datetime的默认值为null,timestamp的默认值不为null,且为系统当前时间。
2.datetime占用8个字节,timestamp占用4个字节。timestamp利用率更高。
3.二者存储方式不一样,对于timestamp,它把客户端插入的时间从当前时区转化为世
界标准时间(UTC)进行存储,查询时,逆向返回。但对于datetime,基本上存什么
是什么。
4.二者范围不一样。
创建数据:
--新建表
create table json_user (
uid int auto_increment,
data json,
primary key(uid)
);
--插入数据
insert into json_user values (
null, '{
"name":"mark",
"age":18,
"address":"xxxx"
}' );
insert into json_user values (
null,
'{
"name":"zhangsan",
"age":28,
"mail":"[email protected]"
}');
select json_extract('[10, 20, [30, 40]]', '$[1]');
select json_extract(data, '$.name'), json_extract(data, '$.address') from json_user;
select json_object("name", "dev", "email", "xxx.com", "age",35); --name:dev,email:xxx.com,age:35
原来有值的,不覆盖;没有的,新增的插入
set @json = '{ "a": 1, "b": [2, 3]}';--一个@局部,两个@@系统
select json_insert(@json, '$.a', 10, '$.c', '[true, false]');
相同key的合并成列表
select json_merge('{"name": "dev"}', '{"id": 47}');
JSON 类型数据本身无法直接创建索引,需要将需要索引的JSON 数据重新生成虚拟列(Virtual Columns) 之后,对该列进行索引
create table test_inex_1(
data json,
gen_col varchar(10) generated always as (json_extract(data, '$.name')),
index idx (gen_col)
);