//登錄MYSQL
@>mysql -u root -p
@>密碼
//創(chuàng)建用戶
insert into mysql.user(host,user,password) values ("localhost","hbchen",p
assword("hbchen"));
這樣就創(chuàng)建了一個(gè)名為:hbchen 密碼為:hbchen (的)用戶。
然后登錄一下。
mysql>exit;
@>mysql -u hbchen -p
@>輸入密碼
mysql>登錄成功
2.為用戶授權(quán)。
//登錄MYSQL(有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 hbchen@localhost identified by 'hbchen';
//刷新系統(tǒng)權(quán)限表
mysql>flush privileges;
mysql>其它們操作
/*
如果想指定部分權(quán)限給一用戶,可以這樣來(lái)寫:
mysql>grant select,update on phplampDB.* to hbchen@localhost identified by 'hbchen';
//刷新系統(tǒng)權(quán)限表。
mysql>flush privileges;
*/
3.刪除用戶。
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User="hbchen" and Host="localhost";
mysql>flush privileges;
//刪除用戶(的)數(shù)據(jù)庫(kù)
mysql>drop database phplampDB;
4.修改指定用戶密碼。
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="hbchen" 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ù)表名;
例如:--新建用戶
insert into mysql.user(host,user,password) values ("localhost","hbchen",p
assword("hbchen"));
---授予權(quán)限
grant all privileges on mysql.* to hbchen@localhost identified by 'hbchen';
--授予部分權(quán)限
grant select,update on mysql.* to hbhcen@localhost identified by 'hbchen';
--更改密碼
update mysql.user set password='123456'where User='hbchen';
use mysql;
update user set password=password('hahaha') where user='hbchen';
--刷新
flush privileges;