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

How to use vue filter

Table of contents Overview Defining filters Use o...

HTML code to add quantity badge to message button

HTML code: <a onclick="goMessage();"...

Implementation of Docker to build private warehouse (registry and Harbor)

As more and more Docker images are used, there ne...

Hexadecimal color codes (full)

Red and pink, and their hexadecimal codes. #99003...

Summary of ten Linux command aliases that can improve efficiency

Preface Engineers working in the Linux environmen...

Implementing a simple age calculator based on HTML+JS

Table of contents Preface Demonstration effect HT...

Solve the problem of inconsistency between mysql time and system time in docker

Recently, when I installed MySQL in Docker, I fou...

Implementation of React virtual list

Table of contents 1. Background 2. What is a virt...

Steps to package and deploy the Vue project to the Apache server

In the development environment, the vue project i...

In-depth explanation of MySQL common index and unique index

Scenario 1. Maintain a citizen system with a fiel...