创建数据库
create database if not exists 数据库名称 default character set utf8 collate utf8_general_ci;
删除数据库
drop database 数据库名称;
创建用户
create user 用户名@‘localhost’ identified by ‘密码’;
‘localhost’ 表示该用户只能本地登录,’%’ 表示可以是任意主机远程登录,也可以指定IP地址
查询用户
select user,host from mysql.user;
更改密码
alter user 用户名@‘localhost’ identified by ‘新密码’;
删除用户
drop user 用户名@‘localhost’;
若创建用户时允许任意主机远程登录,将localhost改成%
远程权限
授权用户对数据库所有权限
grant all privileges on 库名.表名 to 用户名@’%’ with grant option;
库名:数据库名称。所有数据库使用*
表名:数据库的表的名称。所有表使用*
with grant option:表示它具有grant权限,可以将权限传递给其他用户
授权用户对数据库中表的创建,修改,删除以及表数据的增删改查权限
grant create,alter,drop,select,insert,update,delete on 库名.* to 用户名@’%’;
取消授权用户对数据库所有权限
revoke all on 库名.表名 from 用户名@’%’;
查看用户权限
show grants for 用户名@‘localhost’;
刷新权限
flush privileges;