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

MySQL add users, delete users, and authorize

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

MySQL add users, delete users, and authorize

Add users to MySql, create new databases, authorize users, delete users, and change passwords (note that each line is followed by a; indicates the end of a command statement):

1. New user

1.1 Log in to MYSQL:

@ > mysql-u root-p

@ > password

1.2 create a user:

Mysql > insert into mysql.user (Host,User,Password) values ("localhost", "test", password ("1234"))

This creates a user named: test password: 1234.

Note: the "localhost" here means that the user can only log in locally, not remotely on another machine. If you want to log in remotely, change "localhost" to "%", which means you can log in on any computer. You can also specify that a machine can log in remotely.

1.3 then log in:

Mysql > exit

@ > mysql-u test-p

@ > enter your password

Mysql > Login succeeded

two。 Authorize the user

Authorization format: grant permission on database. * to user name @ login host identified by "password"

2.1 Log in to MYSQL (with ROOT permission). Log in here as ROOT:

@ > mysql-u root-p

@ > password

2.2 first create a database (testDB) for the user:

Mysql > create database testDB

2.3 authorized test users have all the permissions of the testDB database (all permissions of a database):

Mysql > grant all privileges on testDB.* to test@localhost identified by '1234'

Mysql > flush privileges;// refresh the system permissions table

Format: grant permission on database. * to user name @ login host identified by "password"

2.4 if you want to assign partial permissions to a user, you can write as follows:

Mysql > grant select,update on testDB.* to test@localhost identified by '1234'

Mysql > flush privileges; / / refresh the system permissions table

2.5 authorized test users have certain permissions for all databases:

Mysql > grant select,delete,update,create,drop on. To test @ "%" identified by "1234"

/ / the test user has select,delete,update,create,drop permissions on all databases.

/ / @ "%" indicates authorization for all non-local hosts, excluding localhost. (the localhost address is set to 127.0.0.1. If it is set to the real local address, I do not know whether it is possible or not, and there is no verification. )

/ / A pair of localhost licenses: add the sentence grant all privileges on testDB.* to test@localhost identified by '1234 licenses;.

Delete user

@ > mysql-u root-p

@ > password

Mysql > Delete FROM user Where User='test' and Host='localhost'

Mysql > flush privileges

Mysql > drop database testDB; / / Delete the user's database

Delete account and permissions: > drop user user name @'%'

Drop user user name @ localhost

Modify the specified user password

@ > mysql-u root-p

@ > password

Mysql > update mysql.user set password=password ('new password') where User= "test" and Host= "localhost"

Mysql > flush privileges

List all databases

Mysql > show database

Switch database

Mysql > use 'database name'

List all tables

Mysql > show tables

Show data table structure

Mysql > describe table name

Delete databases and data tables

Mysql > drop database database name

Mysql > drop table datasheet name

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

Servers

Wechat

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

12
Report