mysql user and user authorization

1.1 Create a mysql user

mysql> create user test identified by 'test';

1.2 authorized users back without identified.

grant select on test.* to test@localhost;

 

1.3 Check MYSQL database for all users
select distinct concat ( 'User:' '', user, '' '@' '', host, '' ';') AS query FROM mysql.user;

or

select user,host  FROM mysql.user;

delete users:

mysql>Delete FROM user Where User='test' and Host='localhost';

mysql>flush privileges;

mysql> drop database testDB; // delete the user database

Delete accounts and privileges:> drop user username @ '%';

        > Drop user username @ localhost;

Authorized users:

Authorized format: grant permission on the database * to username @ log on the host identified by "password";.

  • Authorized test user has all privileges (all privileges of a database) testDB database:

   mysql>grant all privileges on testDB.* to test@localhost identified by '1234';

  mysql> flush privileges; // Refresh system permissions table

 

Some revoke a user's privileges

revoke select on test.* from test;


2. Check the database specific to a user's privileges
mysql> show grants for 'abcuser' @ 'localhost';

Format: show grants for 'user name' @ 'sign in the host';

or

mysql> show grants for abcuser @ 'localhost'; // quotes may be omitted username

If the list displays the user's permissions are as follows:

mysql >select * from mysql.user where user='cactiuser' \G

 


3. See table structure needs of a particular user entry table structure may be combined to query
mysql> desc mysql.user;

 

Display Data Table Structure

mysql>describe 表名;


4. Example 1, add a user password for test1 abc, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First to root user connected to the MYSQL, and then type the following command:
Grant the SELECT, INSERT, Update, the Delete ON * * to test1 @ "%" Identified by "abc";.

But Example 1 increased user is very dangerous, you would like to know as someone test1 password, then he can log your mysql database and your data can do whatever they want, the solution, see Example 2 on any computer on the internet.

Example 2, add a user test2 password is abc, so that he can only log on localhost, and can query the database mydb, insert, modify, delete operations (localhost means the local host, namely that host MYSQL database resides) so that users know that the use test2 password, he can not directly access the database from the internet, you can only be accessed through the web page on the MYSQL host.
. grant select, insert, update, delete on mydb * to test2 @ localhost identified by "abc";

 

If you do not want test2 password, you can resort to a command to eliminate the password.

grant select,insert,update,delete on mydb.* to test2@localhost identified by "";


5. Modify the root password mysql

The first ︰ using a set password syntax

mysq>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

The second:

Edit user table directly using UPDATE

  mysql -u root

  mysql> use mysql;

  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';

  mysql> FLUSH PRIVILEGES;

 

 

In the lost root password, they can so

  mysqld_safe --skip-grant-tables&

  mysql -u root mysql

  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

  mysql> FLUSH PRIVILEGES;

Guess you like

Origin www.cnblogs.com/knight-zhou/p/12067523.html