Mysql new user and delete user specific operation command _ MySQL

Source: Internet
Author: User
Method 1: Using mysqlroot (root permission) user login direct authorization can also create a user usrbinmysqladmin-urootpassword123456mysql-uroot-p password to view all user names and passwords selecthost, user, passwordf Method 1: using mysql root (root permission) you can directly grant permissions when logging on to a user or create a user.
/Usr/bin/mysqladmin-u root password 123456


Mysql-uroot-p
Password
View all user names and passwords
Select host, user, password from user;

Grant all on ec. * to 'root' @ '%' identified by '123 ';
Grant all privileges on ec. * to 'cockpit' @ '% 'identified by '123 ';
Grant all on ec. * to 'cockpit' @ '%' identified by '123 ';
Grant all privileges on ec. * to 'cockpit' @ '% 'identified by '123 ';
Flush privileges ;;

Change database password
User mysql

Modify the password of a mysql database
UPDATE user SET Password = PASSWORD ('000000') where USER = 'root ';
Mysql root password is empty. No password is required for login.
UPDATE user SET Password = PASSWORD (null) where USER = 'root ';
Flush privileges;

Method 2:
1. create a user.
// Log on to MYSQL
@> Mysql-u root-p
@> Password
// Create a database (testDB) for the user first)
Mysql> create database testDB default character set utf8 ;;
// Create a user
Mysql> insert into mysql. user (Host, User, Password) values ("localhost", "test", password ("1234 "));
// Refresh the system permission list
Mysql> flush privileges;
In this way, a user named: test password: 1234 is created.
Then log on.
Mysql> exit;
@> Mysql-u phplamp-p
@> Enter the password
Mysql> logon successful
2. authorize the user.
Format: grant permission on database. * to username @ login host identified by "password ";
> Grant all privileges on phplampDB. * to phplamp @ localhost identified by '100 ";

Authorize the test user to have certain permissions on all databases:
Mysql> grant select, delete, update, create, drop on *. * to test @ "%" identified by "1234 ";

// The test user has the select, delete, update, create, and drop permissions on all databases.

// @ "%" Indicates authorizing all non-local hosts, excluding localhost. (The localhost address is set to 127.0.0.1. if it is set to a real local address, you do not know if it is OK. No verification is performed .)

// Authorize localhost: add the grant all privileges on testDB. * to test @ localhost identified by '20140901.

3. delete a user.
@> Mysql-u root-p
@> Password
Mysql> delete from user WHERE User = "test" and Host = "localhost ";
Mysql> flush privileges;
// Delete the user's database
Mysql> drop database testDB;
4. modify the password of the specified user.
@> Mysql-u root-p
@> Password
Mysql> update mysql. user set password = password ('New password') where User = "test" and Host = "localhost ";
Mysql> flush privileges;

Delete from user where User = "test" and Host = "localhost ";

You can also try:

Delete Account 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.