Create and delete user_mysql

Source: Internet
Author: User
Create and delete mysql users 1. log on to mysql remotely

Mysql-h ip-u root-p password

2. create a user

Format: grant permission on database. * to username @ login host identified by "password ";

Example 1: Add a test1 user with a password of 123456. you can log on to any host and query, add, modify, and delete all databases. It must be performed under the root user of mysql

Mysql> grant select, insert, update, delete on *. * to test1 @ "%" identified by "123456 ";

Mysql> flush privileges;

Example 2: Add a test2 user with a password of 123456. you can only log on to 192.168.2.12 and query, add, modify, and delete student in the database. It must be performed under the root user of mysql

Mysql> grant select, insert, update, delete on student. * to test2@192.168.2.12 identified by "123456 ";

Mysql> flush privileges;

Example 3: Authorize User test3 to have all the permissions of database student

Mysql> grant all privileges on student. * to test3 @ localhost identified by '123 ';

Mysql> flush privileges;

3. change user password

Mysql> update mysql. user set password = password ('000000') where User = 'test1' and Host = 'localhost ';

Mysql> flush privileges;

4. delete a user

Mysql> delete from user where user = 'test2' and host = 'localhost ';

Mysql> flush privileges;

5. delete databases and tables

Mysql> drop database name;

Mysql> drop table name;

6. delete accounts and permissions

Drop user username @ '%'

Drop user username @ localhost

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.