第一步使用root登录mysql

  1. [www@bobo ~]$ mysql -uroot -p
  2. Enter password:
  3. mysql>

第二步为用户授权

授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;
假设我们已经有test数据库,没有需要先建数据库

  1. 授权bobo用户拥有test数据库的所有权限(某个数据库的所有权限)

    1. mysql>grant all privileges on test.* to bobo@localhost identified by '1234';
    2. mysql>flush privileges;//刷新系统权限表
  2. 指定部分权限给用户

    1. mysql>grant select,update on test.* to bobo@localhost identified by '1234';
    2. mysql>flush privileges; //刷新系统权限表
  3. 授权bobo用户拥有所有数据库的某些权限

    1. mysql>grant select,delete,update,create,drop on *.* to bobo@"%" identified by "1234";
    2. mysql>flush privileges; //刷新系统权限表

    bobo用户对所有数据库都有select,delete,update,create,drop 权限。@”%” 表示对所有非本地主机授权,不包括localhost。(localhost地址设为127.0.0.1,如果设为真实的本地地址,不知道是否可以,没有验证。)
    对localhost授权:加上一句grant all privileges on test.* to bobo@localhost identified by ‘1234’;即可。

more

  1. 删除用户
    1. mysql>Delete FROM user Where User='test' and Host='localhost';
    2. mysql>flush privileges;
  2. 删除账户及权限
    1. mysql>drop user 用户名@'%';
    2. mysql>drop user 用户名@ localhost;