(转)mysql常用命令

原文:https://www.cnblogs.com/gychomie/p/11013442.html

启动

service mysqld start

关闭

service mysqld stop

重启

service mysqld restart

查看状态

service mysqld status

查看系统配置

cat /etc/my.conf

创建用户

create user '用户名'@'localhost' identified by '‘密码'; --localhost仅本地连接,也可指定ip,使用%是所有ip可连

flush privileges;--刷新权限,只有刷新后才可以用

修改密码

Alter user 'test1'@'localhost' identified by '新密码';

flush privileges;

授权

grant all privileges on . to 'test1'@'localhost' with grant option;

with gran option表示该用户可给其它用户赋予权限,但不可能超过该用户已有的权限

比如a用户有select,insert权限,也可给其它用户赋权,但它不可能给其它用户赋delete权限,除了select,insert以外的都不能

这句话可加可不加,视情况而定。

all privileges 可换成select,update,insert,delete,drop,create等操作

如:grant select,insert,update,delete on . to 'test1'@'localhost';

第一个*表示通配数据库,可指定新建用户只可操作的数据库

如:grant all privileges on 数据库.* to 'test1'@'localhost';

第二个*表示通配表,可指定新建用户只可操作的数据库下的某个表

如:grant all privileges on 数据库.指定表名 to 'test1'@'localhost';

查看用户授权信息

show grants for 'test1'@'localhost';

撤销权限

revoke all privileges on . from 'test1'@'localhost';

用户有什么权限就撤什么权限

删除用户

drop user 'test1'@'localhost';

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。