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

A brief discussion on the performance issues of MySQL paging limit

MySQL paging queries are usually implemented thro...

Detailed explanation of Vue life cycle functions

Table of contents Lifecycle Functions Common life...

Sample code for nginx to achieve dynamic and static separation

1. Simple configuration of nginx's dynamic an...

Usage and scenario analysis of npx command in Node.js

npx usage tutorial Tonight, when I was learning V...

How to configure wordpress with nginx

Before, I had built WordPress myself, but at that...

Understanding v-bind in vue

Table of contents 1. Analysis of key source code ...

Vue uses dynamic components to achieve TAB switching effect

Table of contents Problem Description What is Vue...

Example of fork and mutex lock process in Linux multithreading

Table of contents Question: 1. First attempt 2. R...

Optimize the storage efficiency of BLOB and TEXT columns in InnoDB tables

First, let's introduce a few key points about...

Why is the disk space still occupied after deleting table data in MySQL?

Table of contents 1. Mysql data structure 2. The ...

Detailed explanation of MySQL joint query optimization mechanism

Table of contents MySQL federated query execution...

MySQL optimization solution: enable slow query log

Table of contents Preface Setting up slow query l...

Determine the direction of mouse entry based on CSS

In a front-end technology group before, a group m...

Comparison of CSS shadow effects: drop-Shadow and box-Shadow

Drop-shadow and box-shadow are both CSS propertie...