The second MySQL common Operation Record (reprint)

Source: Internet
Author: User

When we create a website, we generally need to use a database. For security reasons, non-root users are recommended. Common commands are as follows:

1. Create a new user

Log in to MySQL
@>mysql-u root-p
@> Password
Create user
mysql> INSERT INTO Mysql.user (Host,user,password) VALUES (' localhost ', ' Allen ', Password (' Allen '));
Refresh System Permissions Table
Mysql>flush privileges;
This creates a user named Allen with the password: Allen.

Log in after exiting
mysql>exit;
@>mysql-u allen-p
@> Enter password
Mysql> Login Successful

2. Authorizing the user

Log in to MySQL (with root privileges). I am logged in as root.
@>mysql-u root-p
@> Password
First create a database for the user (ALLENDB)
Mysql>create database allendb;
Empower Allen users to have all the permissions of the Allen database
@>grant all on allendb.* to Allen@localhost identified by ' Allen ';
Refresh System Permissions Table
Mysql>flush privileges;
Mysql> Other operations

If you want to specify partial permissions to a user, you can write:
Mysql>grant select,update on jeecndb.* to Allen@localhost identified by ' Allen ';
Refreshes the System permissions table.
Mysql>flush privileges;

Mysql> grant permissions 1, permissions 2,... Permission n on the database name. Table name to User name @ user address identified by ' connection password ';

Permissions 1, Permissions 2,... Permission n represents 14 permissions, such as Select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file.
When permissions 1, permissions 2,... Permission n is replaced by all privileges or all to give the user full permission.

The second MySQL common Operation Record (reprint)

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.