Example of how to create a local user in mysql and grant database permissions

Example of how to create a local user in mysql and grant database permissions

Preface

When you install MySQL, you usually create a superuser root. Many people continue to use this user. Although this is convenient, the superuser has too much authority, and using it everywhere is usually a security risk.

This is similar to the user management of the operating system. Most people use the administrator or root user directly for convenience, which is actually not a recommended practice.

So, how do you create a user other than root in MySQL and grant corresponding permissions?

Let's look at an example directly:

CREATE USER 'golden'@'localhost' IDENTIFIED BY 'gd2017';
GRANT ALL ON myapp.* TO 'golden'@'localhost';
FLUSH PRIVILEGES;

Here is a brief analysis of the above statement:

1. The create user statement is used to create a user (and password).

Here golden is the username and gd2017 is the password. localhost indicates a local user.

2. The grant statement is used to grant permissions to users.

Among them, all means all permissions, including adding, deleting, modifying and checking data and changing the database; myapp is the name of a specific database, myapp.* means all tables (and views, etc.) under the database; golden is the user name just created.

3. The flush statement makes the changes effective.

expand:

Usually, the above settings can meet general needs. For more detailed configuration, please refer to the official online documentation of MySQL (version 5.7):

https://dev.mysql.com/doc/refman/5.7/en/create-user.html

https://dev.mysql.com/doc/refman/5.7/en/grant.html

Summarize

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Solve the problem of Django writing Chinese characters to MySQL
  • Solution to the error of inserting Chinese characters into MySQL under centOS7
  • How to avoid garbled characters when accessing Chinese characters in C# and MySQL
  • Solve the problem of Access denied for user ''root''@''%'' to database ''xxx'' after creating a database in MySQL
  • How to create a MySQL database and support Chinese characters

<<:  Vue data two-way binding implementation method

>>:  How to use boost.python to call c++ dynamic library in linux

Recommend

MySQL uses SQL statements to modify table names

In MySQL, you can use the SQL statement rename ta...

MySQL cleverly uses sum, case and when to optimize statistical queries

I was recently working on a project at the compan...

Introduction to common MySQL storage engines and parameter setting and tuning

MyISAM, a commonly used storage engine in MySQL c...

SQL GROUP BY detailed explanation and simple example

The GROUP BY statement is used in conjunction wit...

Proxy_pass method in multiple if in nginx location

1. First, let's review the relevant knowledge...

Improvements to the web server to improve website performance

<br />In the first section of this series, w...

jQuery implements the function of adding and deleting employee information

This article shares the specific code of jQuery t...

Explanation of the execution priority of mySQL keywords

As shown below: from table where condition group ...

7 ways to vertically center elements with CSS

【1】Know the width and height of the centered elem...

Use label tag to select the radio button by clicking the text

The <label> tag defines a label (tag) for an...

React introduces antd-mobile+postcss to build mobile terminal

Install antd-mobile Global import npm install ant...

Detailed tutorial on Docker pulling Oracle 11g image configuration

Without further ado Start recording docker pullin...

Ubuntu 16.04 64-bit compatible with 32-bit programs in three steps

Step 1: Confirm the architecture of your system d...