Get the App
SLTechnology News&Howtos  ›  Database  › 

How to create new users, authorize and delete users, and change passwords in MySQL

Shulou Source: shulou.com Published: 2022-05-31 12:57:35 09月25日 Update

This article will explain in detail how to create new MySQL users, authorize and delete users and change passwords. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

First of all, let's make it clear: in general, to change the MySQL password and authorization, you need to have the root permission in mysql.

Note: this operation is at the WIN command prompt, phpMyAdmin is also applicable.

User: phplamp user database: phplampDB

1. Create a new user.

/ / Log in to MYSQL

@ > mysql-u root-p

@ > password

/ / create a user

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

/ / refresh the system permissions table

Mysql > flush privileges

This creates a user named: phplamp password: 1234.

And log in.

Mysql > exit

@ > mysql-u phplamp-p

@ > enter your password

Mysql > Login succeeded

two。 Authorize the user.

/ / Log in to MYSQL (with ROOT permission). I log in as ROOT.

@ > mysql-u root-p

@ > password

/ / first create a database (phplampDB) for the user

Mysql > create database phplampDB

/ / authorized phplamp users have all permissions in the phplamp database.

> grant all privileges on phplampDB.* to phplamp@localhost identified by '1234'

/ / refresh the system permissions table

Mysql > flush privileges

Mysql > other actions

/ *

If you want to assign partial permissions to a user, you can write like this:

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

/ / refresh the system permission table.

Mysql > flush privileges

, /

3. Delete the user.

@ > mysql-u root-p

@ > password

Mysql > DELETE FROM user WHERE User= "phplamp" and Host= "localhost"

Mysql > flush privileges

/ / Delete the user's database

Mysql > drop database phplampDB

4. Modifies the specified user password.

@ > mysql-u root-p

@ > password

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

Mysql > flush privileges

This is the end of how to create new users, authorize and delete users and change passwords in MySQL. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Tags: User password permission login data database system content article more knowledge article not bad success command situation prompt is in quality identity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei MariaDB Linux OPPO Reno