摘要
开发者必备Mysql常用命令,涵盖了数据定义语句、数据操纵语句及数据控制语句,基于Mysql5.7。
数据定义语句(DDL)
表操作
- 查看表的定义
show create table table_name;
数据控制语句(DCL)
- 查看账号权限
show grants for ‘test’@‘localhost’
- 收回操作权限
revoke insert on test.* from ‘test’@‘localhost’
- 授予所有数据库的所有权限
grant all privileges on . to ‘test’@‘localhost’
其他
字符集相关
- 查看字符集
show variables like ‘character%’
- 创建数据库时指定字符集
create database test2 character set utf8
时区相关
- 查看当前时区(UTC为世界统一时间,中国为UTC+8)
show variables like “%time_zone%”
- 修改mysql全局时区为北京时间,即我们所在的东8区
set global time_zone = ‘+8:00’;
- 修改当前会话时区
set time_zone = ‘+8:00’
- 立即生效
flush privileges