MySQL添加授權(quán)的用戶命令實(shí)際操作
我們今天是要和大家一起探討的是MySQL添加授權(quán)的用戶命令 ,我前兩天在相關(guān)網(wǎng)站看見(jiàn)MySQL添加授權(quán)的用戶命令的資料,覺(jué)得挺好,就拿出來(lái)供大家分享。希望會(huì)給你帶來(lái)一些幫助在此方面。
1.新建用戶。
登錄MySQL
@>MySQL -u root -p
@>密碼
創(chuàng)建用戶
- MySQL> mysql> insert into MySQL.user(Host,User,Password,ssl_cipher,x509_issuer,x509_sub
- ject) values("localhost","pppadmin",password("passwd"),'','','');
這樣就創(chuàng)建了一個(gè)名為:phplamp 密碼為:1234 的用戶。
然后登錄一下。
- MySQL>exit;
- @>MySQL -u phplamp -p
@>輸入密碼
MySQL>登錄成功
2.為用戶授權(quán)。
登錄MySQL添加授權(quán)(有ROOT權(quán)限)。我里我以ROOT身份登錄.
@>MySQL -u root -p
@>密碼
首先為用戶創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)(phplampDB)
- MySQL>create database phplampDB;
授權(quán)phplamp用戶擁有phplamp數(shù)據(jù)庫(kù)的所有權(quán)限。
- >grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';
刷新系統(tǒng)權(quán)限表
- MySQL>flush privileges;
MySQL添加授權(quán)>其它操作
/*
如果想指定部分權(quán)限給一用戶,可以這樣來(lái)寫(xiě):
- MySQL>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';
刷新系統(tǒng)權(quán)限表。
- MySQL>flush privileges;
*/
3.刪除用戶。
@>MySQL -u root -p
@>密碼
- MySQL>Delete FROM user Where User="phplamp" and Host="localhost";
- MySQL>flush privileges;
刪除用戶的數(shù)據(jù)庫(kù)
- MySQL>drop database phplampDB;
4.修改指定用戶密碼。
@>MySQL -u root -p
@>密碼
- MySQL>update MySQL.user set passwordpassword=password('新密碼') where User="phplamp" and Host="localhost";
- MySQL>flush privileges;
5.列出所有數(shù)據(jù)庫(kù)
- MySQL>show database;
6.切換數(shù)據(jù)庫(kù)
MySQL>use '數(shù)據(jù)庫(kù)名';
7.列出所有表
- MySQL>show tables;
8.顯示數(shù)據(jù)表結(jié)構(gòu)
- MySQL>describe 表名;
9.刪除數(shù)據(jù)庫(kù)和數(shù)據(jù)表
- MySQL>drop database 數(shù)據(jù)庫(kù)名;
MySQL>drop table 數(shù)據(jù)表名; Tag標(biāo)簽: MySQL添加授權(quán)命令
【編輯推薦】
- MySQL heap使用大匯總
- 如何用PHP來(lái)實(shí)現(xiàn)MySQL備份?
- MySQL轉(zhuǎn)義字符的實(shí)際應(yīng)用
- MySQL常用技巧都包括哪些?
- MySQL 備份的實(shí)際應(yīng)用與功能介紹