三、增加新用戶。(注意:和上面不同,下面的因為是MySQL環(huán)境中的命令,所以后面都帶一個分號作為命令結(jié)束符)
格式:grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by \"密碼\"
例1、增加一個用戶test1密碼為abc,讓他可以在任何主機上登錄,并對所有數(shù)據(jù)庫有查詢、插入、修改、刪除的權(quán)限。首先用以root用戶連入MySQL,然后鍵入以下命令:
grant select,insert,update,
delete on *.* to test2@localhost identified by \"abc\";
如果你不想test2有密碼,可以再打一個命令將密碼消掉。
grant select,insert,update,delete on mydb
.* to test2@localhost identified by \"\";
在上面講了登錄、增加用戶、密碼更改等問題。下面我們來看看MySQL中有關(guān)數(shù)據(jù)庫方面的操作。注意:你必須首先登錄到MySQL中,以下操作都是在MySQL的提示符下進行的,而且每個命令以分號結(jié)束。
1、MySQL常用命令
create database name; 創(chuàng)建數(shù)據(jù)庫
use databasename; 選擇數(shù)據(jù)庫
drop database name 直接刪除數(shù)據(jù)庫,不提醒
show tables; 顯示表
describe tablename; 表的詳細描述
select 中加上distinct去除重復字段
mysqladmin drop database name 刪除數(shù)據(jù)庫前,有提示。
顯示當前mysql版本和當前日期
select version(),current_date;
2、修改mysql中root的密碼:
shell>mysql -u root -p
mysql> update user set password=password(”xueok654123″) where user=’root’;
mysql> flush privileges //刷新數(shù)據(jù)庫
mysql>use dbname; 打開數(shù)據(jù)庫:
mysql>show databases; 顯示所有數(shù)據(jù)庫
mysql>show tables; 顯示數(shù)據(jù)庫mysql中所有的表:先use mysql;然后
mysql>describe user; 顯示表mysql數(shù)據(jù)庫中user表的列信息);
3、grant
創(chuàng)建一個可以從任何地方連接服務(wù)器的一個完全的超級用戶,但是必須使用一個口令something做這個
mysql> grant all privileges on *.* to user@localhost identified by ’something’ with
增加新用戶
格式:grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by “密碼”
GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY ’something’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO monty@”%” IDENTIFIED BY ’something’ WITH GRANT OPTION;
刪除授權(quán):
mysql> revoke all privileges on *.* from root@”%”;
mysql> delete from user where user=”root” and host=”%”;
mysql> flush privileges;
創(chuàng)建一個用戶custom在特定客戶端it363.com登錄,可訪問特定數(shù)據(jù)庫fangchandb
mysql >grant select, insert, update, delete, create,drop on fangchandb.* to custom@ it363.com identified by ‘ passwd’
重命名表:
mysql > alter table t1 rename t2;
4、mysqldump