Share new users and authorization methods in Mysql, and authorize mysql
In the project development process, you may need to open your own database to others, but to ensure security, you cannot open other databases on your server at the same time. You can create a new user and grant the user specific database permissions.
Test environment: Centos 6.3 and Mysql 5.3
1. Create a user
Copy codeThe Code is as follows:
// Log on to MYSQL
@> Mysql-u root-p
@> Password
// Create a user
Mysql> insert into mysql. user (Host, User, Password) values ("localhost", "cplusplus", password ("cplusplus. me "));
// Refresh the system permission list
Mysql> flush privileges;
In this way, a user named cplusplus with the password cplusplus. me is created.
Ii. logon Test
Mysql> exit; @> mysql-u cplusplus-p @> enter the password mysql> login successful
Iii. user authorization
// Log on to MYSQL @> mysql-u root-p @> password // first create a database (cplusplusDB) for the user mysql> create database cplusplusDB; // authorize the cplusplus user to have all permissions for the cplusplusDB database.> Grant all privileges on cplusplusDB. * to cplusplus @ localhost identified by 'cplusplus. Me'; // refresh the system permission table mysql> flush privileges; mysql> other operations
Iv. Partial authorization
Mysql> grant select, update on cplusplusDB. * to cplusplus @ localhost identified by 'cplusplus. Me'; // refresh the system permission table. Mysql> flush privileges;
5. delete a user
@> Mysql-u root-p @> password mysql> delete from user WHERE User = "cplusplus" and Host = "localhost"; mysql> flush privileges;
6. delete a database
mysql>drop database cplusplusDB;
7. Change the password
@> Mysql-u root-p @> password mysql> update mysql. user set password = password ('new password') where User = "cplusplus" and Host = "localhost"; mysql> flush privileges;
Share with you the experience of a netizen:
1. Create a user
Log on to mysql with the root permission and create a new user with the same name as the database.
mysql> INSERT INTO mysql.user(Host,User,Password) VALUES('localhost', 'sun', password('sun123456'));
Refresh system permission list
mysql> FLUSH PRIVILEGES;
If an error is reported
#1364 – Field ‘ssl_cipher' doesn't have a default value
Change the MySQL configuration file to my. cnf in linux and my. ini in windows.
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
Change
sql_mode=NO_ENGINE_SUBSTITUTION
Restart MySQL Service
2. Authorize the user
mysql> GRANT ALL ON sun.* to sun@localhost identified BY 'sun123456';mysql> FLUSH PRIVILEGES;