Mysql的基本操作

# 创建数据库
$ create database wordpress 

# 删除数据库
$ drop database wordpress

# 添加mysql用户
$ CREATE USER 'username'@'host' IDENTIFIED BY 'password';
$ create user 'wbl'@'%' identified by '123456';
$ create user 'wbl'@'114.112.154.151' # 不需要密码登陆

# 授权用户
$ GRANT privileges ON databasename.tablename TO 'username'@'host'
$ GRANT SELECT, INSERT ON test.user TO 'wbl'@'%';
$ GRANT ALL ON *.* TO 'wbl'@'%';
# 让该用户可以授权,用以下命令:
$ GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

# 设置密码
$ SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');

# 当前用户
$ SET PASSWORD = PASSWORD("newpassword");

# 撤销用户权限
$ REVOKE privilege ON databasename.tablename FROM 'username'@'host';
$ REVOKE SELECT ON *.* FROM 'wbl'@'%';

# 查看授权信息
$ SHOW GRANTS FOR 'wbl'@'%';

# 删除用户
$ DROP USER 'username'@'host';

# 刷新数据库
$ flush privileges;

你可能感兴趣的:(Mysql的基本操作)