Mysql creates and deletes root users and common users, and modifies and deletes root users.

Source: Internet
Author: User

Mysql creates and deletes root users and common users, and modifies and deletes root users.

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 the root user has set a password, use the following method:

mysqladmin -u root password oldpass "newpass"

Method 3: Use UPDATE to directly edit the user table 

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

Create a common 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 can be used later. You must use update to update the user table before.

Delete

Mysql> drop user newuser; // When deleting a user before mysql5, you must first use revoke to delete the user permission and then delete the user. After mysql5, you can drop the command to delete the user's permissions while deleting the user.

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;

Revoke permissions

Mysql> revoke select on dmc_db. * from zx_root; // if the permission does not exist, an error is returned.

Modify

Mysql> rename user feng to newuser; // mysql 5 can be used later. You must use update to update the user table before.

Delete

Mysql> dropuser newuser; // When deleting a user before mysql5, you must first use revoke to delete the user permission and then delete the user. After mysql5, you can drop the command to delete the user's permissions while deleting the user.

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;

Revoke permissions

Mysql> revoke select on dmc_db. * from zx_root; // if the permission does not exist, an error is returned.

The above section describes how to create root users and common users and modify and delete functions for mysql. I hope this will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.