MySQL User Management: Add User, Authorize, Delete User

Add User

Login the database with root users and run the following commands:

create user zhangsan identified by 'zhangsan';

The above command creates the user zhangsan with the password zhangsan. In mysql.user table, you can see information about the additional users:

Authorization

Command format: Grant Privilegescode on dbName.table Name to use

grant all privileges on zhangsanDb.* to zhangsan@'%' identified by 'zhangsan';
flush privileges;

The statement above gives zhangsanDb all operating privileges to the user zhangsan. In mysql.db table, you can see information about new database permissions:

It’s also possible.show grantsCommand to view the authority granted for execution:

show grants for 'zhangsan';

privilegesCodeIndicates the type of authority granted, which is commonly used in the following categories:[1]:

  • All privileges.
  • Self: Read permission.
  • Delete: Delete permission.
  • Update: Update permissions.
  • Create permission.
  • Drop: Delete database, data sheet permissions.

dbName.tableNameThe following options are commonly used to indicate a specific library or form for the granting of authority:

  • .: Grant permission to all databases of the database server.
  • dbName.*: Grant permission to all tables in dbName database.
  • dbName.dbTable: Grant permission to dbtable tables in database dbName.

username@hostThis indicates the given user and the IP address that allows the user to log in.

  • localhost:Only the user is allowed to log in locally and not remotely.
  • %:Remote log-in is allowed for any machine other than this one.
  • 192.168.52.32:The specific IP indicates that only the user is allowed to log in from a particular IP.

passwordSpecifies the face of the user when you login.

flush privilegesindicates a refreshing change of permission.

Change Password

Run the following commands to change user password

update mysql.user set password = password('zhangsannew') where user = 'zhangsan' and host = '%';
flush privileges;

Remove User

Run the following commands to delete users:

drop user zhangsan@'%';

The drop user command removes the user and the permission to do so, and you will find that the corresponding records of both mysql.user and mysql.db forms have disappeared after executing the order.

Common Command Group

Create user and grant full permission to specify database: for Web application to create MySQL users

create user zhangsan identified by 'zhangsan';
grant all privileges on zhangsanDb.* to zhangsan@'%' identified by 'zhangsan';
flush  privileges;

Created the user zhangsan and granted all zhangsanDB privileges. If zhangsan can log in from this machine, then more permissions are given to localhost:

grant all privileges on zhangsanDb.* to zhangsan@'localhost' identified by 'zhangsan';

未经允许不得转载:萌萌Apprentissage » MySQL User Management: Add User, Authorize, Delete User

Like (0) 打赏

Comments 0

Protected with IP Blacklist CloudIP Blacklist Cloud
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

//下一个脚本特效
//下一个脚本