MySql中添加用戶,新建數(shù)據(jù)庫,用戶授權,刪除用戶,修改密碼
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)建了一個名為:phplamp 密碼為:1234 的用戶。
然后登錄一下。
mysql>exit;
@>mysql -u phplamp -p
@>輸入密碼
mysql>登錄成功
2.為用戶授權。
//登錄MYSQL(有ROOT權限)。我里我以ROOT身份登錄.
@>mysql -u root -p
@>密碼
//首先為用戶創(chuàng)建一個數(shù)據(jù)庫(phplampDB)
mysql>create database phplampDB;
//授權phplamp用戶擁有phplamp數(shù)據(jù)庫的所有權限。
>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系統(tǒng)權限表
mysql>flush privileges;
mysql>其它操作
/*
如果想指定部分權限給一用戶,可以這樣來寫:
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系統(tǒng)權限表。
mysql>flush privileges;
*/
3.刪除用戶。
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User="phplamp" and Host="localhost";
mysql>flush privileges;
//刪除用戶的數(shù)據(jù)庫
mysql>drop database phplampDB;
4.修改指定用戶密碼。
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="phplamp" and Host="localhost";
mysql>flush privileges;
5.列出所有數(shù)據(jù)庫
mysql>show database;
6.切換數(shù)據(jù)庫
mysql>use '數(shù)據(jù)庫名';
7.列出所有表
mysql>show tables;
8.顯示數(shù)據(jù)表結構
mysql>describe 表名;
9.刪除數(shù)據(jù)庫和數(shù)據(jù)表
mysql>drop database 數(shù)據(jù)庫名;
mysql>drop table 數(shù)據(jù)表名;
posted on 2011-12-27 17:30
Alpha 閱讀(9840)
評論(0) 編輯 收藏 所屬分類:
MySQL NoSQL