Home >Database >Mysql Tutorial >Detailed explanation of mysql's creation of root ordinary users and modification and deletion functions

Detailed explanation of mysql's creation of root ordinary users and modification and deletion functions

小云云
小云云Original
2018-01-27 14:51:141614browse

This article mainly introduces the mysql creation of root users and ordinary users and the modification and deletion functions. Friends in need can refer to it. I hope it can help everyone.

Method 1: Use the SET PASSWORD command

  mysql -u root
  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

Method 2: Use mysqladmin

mysqladmin -u root password "newpass"

If root has already set a password, use the following method

mysqladmin -u root password oldpass "newpass"

Method 3: Edit the user table directly with UPDATE

mysql -u root
  mysql> use mysql;
  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
  mysql> FLUSH PRIVILEGES;

Create a normal user

User management

mysql>use mysql;

View

mysql> select host,user,password from user ;

Create

mysql>

User Management

mysql>use mysql;

View

mysql> select host,user,password from user ;

Create User

mysql> insert into mysql.user (Host,User,Password) Values('%','wise',PASSWORD('passwd'));
msyql>FLUSH RPIVILEGES

Modify

mysql>rename user feng to newuser;//mysql 5之后可以使用,之前需要使用update 更新user表

Delete

mysql>drop user newuser; //mysql5之前删除用户时必须先使用revoke 删除用户权限,然后删除用户,mysql5之后drop 命令可以删除用户的同时删除用户的相关权限

Change password

mysql> set password for zx_root =password('xxxxxx');
 mysql> update mysql.user set password=password('xxxx') where user='otheruser'

View user permissions

mysql> show grants for zx_root;

Grant permissions

mysql> grant all privileges on YQ.* to wise;

Recycle permissions

mysql> revoke select on dmc_db.* from zx_root; //如果权限不存在会报错

Modify

mysql>rename user feng to newuser;//mysql 5之后可以使用,之前需要使用update 更新user表

Delete

mysql>dropuser newuser; //mysql5之前删除用户时必须先使用revoke 删除用户权限,然后删除用户,mysql5之后drop 命令可以删除用户的同时删除用户的相关权限

Change password

mysql> set password for zx_root =password('xxxxxx');
 mysql> update mysql.user set password=password('xxxx') where user='otheruser'

View user permissions

mysql> show grants for zx_root;

Grant permissions

mysql> grant select on dmc_db.* to zx_root;

Recycle permissions

mysql> revoke select on dmc_db.* from zx_root; //如果权限不存在会报错

Related recommendations:

MySQL creates user accounts and deletes user accounts

mysql creates calculated fields and uses subqueries tutorial

Parses mysql to create local Users and granting database permissions

The above is the detailed content of Detailed explanation of mysql's creation of root ordinary users and modification and deletion functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn