New user and authorized method sharing in Mysql _mysql

Source: Internet
Author: User
Tags flush

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

mysql> FLUSH privileges;

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;

Related Article

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.