Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql create new users and databases and authorize

Shulou Source: shulou.com Published: 2022-06-01 17:12:18 10月11日 Update

I. create a new user

/ / Log in to MYSQL

Root@log:~# mysql-uroot-p

Enter password: password

Welcome to the MySQL monitor. Commands end with; or\ g.

Your MySQL connection id is 138

Server version: 5.5.53-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

Affiliates. Other names may be trademarks of their respective

Owners.

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

/ / create a user

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

Mysql > insert into mysql.user (Host,User,Password) values ("%", "zhouyuyao", password ("Zhouyuyao123"))

/ / refresh the system permissions table

Mysql > flush privileges

This creates a user named: zhouyuyao password: Zhouyuyao123.

Second, login test

Mysql > exit

@ > mysql-u zhouyuyao-p

@ > enter your password

Mysql > Login succeeded

III. User authorization

/ / Log in to MYSQL

@ > mysql-u root-p

@ > password

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

Mysql > create database test

/ / authorized zhouyuyao users have all permissions of the test database

Mysql > grant all privileges on test.* to zhouyuyao@'%' identified by 'Zhouyuyao123'

/ / refresh the system permissions table

Mysql > flush privileges

Mysql > other actions

IV. Partial authorization

Mysql > grant select,update on test.* to zhouyuyao@localhost

Identified by 'cplusplus.me'

/ / refresh the system permissions table

Mysql > flush privileges

Delete users

@ > mysql-u root-p

@ > password

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

Mysql > flush privileges

Delete the database

Mysql > drop database test

7. Change the password

@ > mysql-u root-p

@ > password

Mysql > update mysql.user set password=password ('new password') where

User= "zhouyuyao" and Host= "localhost"

Mysql > flush privileges

Tags: User password permissions login data database system success part new secret test input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Shulou Information Redmi OPPO Reno