It may be necessary to open up your own database to others in the course of developing a project, but in order to be safe, it is not possible to open other databases in the server. You can create a new user to open specific database permissions to the user
Test environment: Centos 6.3 and MySQL 5.3
First, new user
Copy Code code as follows:
Login 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 System Permission Table
Mysql>flush privileges;
This creates a user named: cplusplus Password: cplusplus.me.
Second, the login test
mysql>exit;
@>mysql-u cplusplus-p
@> Enter password
mysql> login succeeded
Third, user authorization
Login
to MySQL @>mysql-u root-p
@> password
//First create a database for users (CPLUSPLUSDB)
Mysql>create db Cplusplusdb;
Authorize Cplusplus users to have all the permissions of the CPLUSPLUSDB database.
>grant all privileges in cplusplusdb.* to cplusplus@localhost identified by ' cplusplus.me ';
Refresh System Permission table
Mysql>flush privileges;
mysql> Other actions
Iv. Partial delegation of authority
Mysql>grant select,update on cplusplusdb.* to Cplusplus@localhost identified by ' cplusplus.me ';
Refreshes the System permission table.
Mysql>flush privileges;
V. Delete users
@>mysql-u root-p
@> password
mysql>delete from user WHERE user= "cplusplus" and host= "localhost";
Mysql>flush privileges;
VI. deleting databases
Mysql>drop database Cplusplusdb;
Seven, modify 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;
To share a friend's experience:
1. New User
User root permissions login to MySQL, 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 Table
If the error
#1364 –field ' ssl_cipher ' doesn ' t have a default value
Modify MySQL profile Linux system for my.cnf,windows system for My.ini
Sql_mode=no_engine_substitution,strict_trans_tables
Amended to
Sql_mode=no_engine_substitution
Restart the MySQL service
2. Authorize the user
Mysql> GRANT all on sun.* to sun@localhost identified by ' sun123456 ';
mysql> FLUSH privileges;