溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Mysql新建用戶和數(shù)據(jù)庫并授權(quán)

發(fā)布時間:2020-06-10 09:54:19 來源:網(wǎng)絡(luò) 閱讀:382 作者:歸來仍少年 欄目:MySQL數(shù)據(jù)庫


一、新建用戶

//登錄MYSQL

root@log:~# mysql -uroot -p

Enter 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.


//創(chuàng)建用戶

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"));


//刷新系統(tǒng)權(quán)限表

mysql> flush privileges;

這樣就創(chuàng)建了一個名為:zhouyuyao 密碼為:Zhouyuyao123 的用戶。


二、登錄測試

mysql>exit;

@>mysql -u zhouyuyao -p

@>輸入密碼

mysql>登錄成功


三、用戶授權(quán)

//登錄MYSQL

@>mysql -u root -p

@>密碼

//首先為用戶創(chuàng)建一個數(shù)據(jù)庫(test)

mysql>create database test;


//授權(quán)zhouyuyao 用戶擁有test數(shù)據(jù)庫的所有權(quán)限

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


//刷新系統(tǒng)權(quán)限表

mysql> flush privileges;

mysql> 其它操作


四、部分授權(quán)

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

identified by ‘cplusplus.me';


//刷新系統(tǒng)權(quán)限表

mysql> flush privileges;


五、刪除用戶

@>mysql -u root -p

@>密碼

mysql>DELETE FROM user WHERE User=”zhouyuyao” and Host=”localhost”;

mysql> flush privileges;


六、刪除數(shù)據(jù)庫

mysql>drop database test;


七、修改密碼

@>mysql -u root -p

@>密碼

mysql>update mysql.user set password=password(‘新密碼’) where

User=”zhouyuyao” and Host=”localhost”;

mysql> flush privileges;



向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI