Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction of two ways of MySQL Database Authorization

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is about the introduction of two ways to authorize MySQL databases. The secret of the text is that it is close to the topic. So, no gossip, let's go straight to the following, I believe that after reading the two ways of MySQL database authorization this article will certainly benefit you.

Two ways of MySQL Database Authorization

Method 1: create a user and authorize it through the grant command

The simple syntax of the grant command is as follows:

Grant all privileges on dbname.* to username@localhost identified by 'passwd'

The list is as follows:

Note: the above command authorizes all permissions on the localhost host to manage the dbname database through the user username, and the password is passwd. Among them, username,dbname,passwd can be modified according to the business situation.

For example: create a zd user, have all permissions on the test library, and allow login to the management database from the localhost host with a password of 123456.

First, take a look at the current database users:

Mysql > select user,host from mysql.user

Then, execute the following authorization command:

Mysql > grant all on test.* to zd@localhost identified by '123456'

Finally, check the current database user situation:

Mysql > select user,host from mysql.user

View the specific permissions of authorized users:

Mysql > show grants for zd@localhost; (or mysql > show grants for zd@localhost\ G)

Note: you can see that the default permission is usage, that is, the connection permission, followed by the addition of all permission!

Method 2: create and grant matching method

First, create the user username and password passwd, and authorize the host localhost.

Syntax: create user username@localhost identified by 'passwd'

Such as: create user www and password 123456, authorize host localhost.

Mysql > create user www@localhost identified by '123456'

Then authorize all permissions on the localhost host to manage the dbname database through user username without a password.

Syntax: grant all on dbname.* to username@localhost

For example: authorize all permissions of www to manage test database on localhost host.

Mysql > grant all on test.* to zd@localhost

View current user information:

Mysql > select user,host from mysql.user

View the specific permissions of www:

Mysql > show grants for www@localhost; (or mysql > show grants for www@localhost\ G)

Is there anything you don't understand about the above two ways of MySQL database authorization? Or if you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report