Share new users and authorization methods in Mysql, and authorize mysql

Source: Internet
Author: User

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;

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.