mysql常用操作

一.创建用户

  • 执行任何IP的yuhaohao用户登录
    create user 'yuhaohao'@'%' identified by '123456';

  • 执行指定IP的yuhaohao用户登录
    create user 'yuhaohao'@'192.118.1.1' identified by '123456';

二.用户数据库权限操作

  • yuhaohao用户对所有数据库中文件有任何操作
    grant all privileges on . to "yuhaohao"@'%';

表示有所有的权限,除了grant这个命令,这个命令是root才有的。yuhaohao用户对test下的table1文件任意操作权限

grant all privileges on test.table1 to "yuhaohao"@'%';

yuhaohao用户对test数据库中的文件执行任何操作

grant all privileges on test.* to "yuhaohao"@'%';

三.修改数据库的表结构

MySQL [my_device]> desc device_fault;
+------------------+-------------+------+------+-------------------+-----------------------------------------------+
| Field            | Type        | Null | Key  | Default           | Extra                                         |
+------------------+-------------+------+------+-------------------+-----------------------------------------------+
| id               | int(11)     | NO   | PRI  | NULL              | auto_increment                                |
| my_no           | varchar(64) | NO   | UNI  | NULL              |                                               |
| fault_level      | int(11)     | YES  | MUL  | NULL              |                                               |
+------------------+-------------+------+------+-------------------+-----------------------------------------------+

修改fault_level默认值为1,且修改COMMENT注释。

# 修改字段的默认值为1
alter table device_fault alter fault_level set default 1;
# 修改字段的注释alter table table_name modify col_name col_type not null commit '字段注释';
alter table device_fault modify fault_level  int(11) not null default 1 comment '修改后的字段注释';
posted @ 2021-07-13 19:24  yuhaohao  阅读(96)  评论(0编辑  收藏  举报