登錄數(shù)據(jù)庫(kù)語(yǔ)句:
mysql -uroot -p
1、顯示數(shù)據(jù)庫(kù)
show databases;
2、選擇數(shù)據(jù)庫(kù)
use數(shù)據(jù)庫(kù)名;
3、顯示數(shù)據(jù)庫(kù)中的表
show tables;
4、顯示數(shù)據(jù)表的結(jié)構(gòu)
describe 表名;
5、顯示表中記錄
SELECT*FROM表名
6、建庫(kù)
createdatabse 庫(kù)名;
7、建表
create table 表名 (字段設(shè)定列表);
mysql>create table name(->id int auto_increment not null primary key,->uname char(8),->gender char(2),->birthday date );
Query OK,0rows affected (0.03sec)
mysql>show tables;+------------------+|Tables_in_userdb|+------------------+|name|+------------------+1rowinset(0.00sec)
mysql>describe name;+----------+---------+------+-----+---------+----------------+|Field|Type|Null|Key|Default|Extra|+----------+---------+------+-----+---------+----------------+|id|int(11)|NO|PRI|NULL|auto_increment||uname|char(8)|YES||NULL|||gender|char(2)|YES||NULL|||birthday|date|YES||NULL||+----------+---------+------+-----+---------+----------------+4rows inset(0.00sec)
注: auto_increment 自增primary key主鍵
8、增加記錄
insert into name(uname,gender,birthday) values('張三','男','1971-10-01');
9、修改記錄
update name set birthday='1971-01-10' where uname='張三';
10、刪除記錄
delete from name where uname='張三';
11、刪除表
drop table 表名 ? ??
清空表內(nèi)容,不刪除表結(jié)構(gòu)
truncate table '表名'
12、刪除庫(kù)
drop database 庫(kù)名;
13、備份數(shù)據(jù)庫(kù)
mysqldump -uroot -p --opt 數(shù)據(jù)庫(kù)名 > 備份名; //進(jìn)入到庫(kù)目錄
14、恢復(fù)
mysql -uroot -p 數(shù)據(jù)庫(kù)名 < 備份名;//恢復(fù)時(shí)數(shù)據(jù)庫(kù)必須存在,可以為空數(shù)據(jù)庫(kù)
15、數(shù)據(jù)庫(kù)授權(quán)
格式:grant select on 數(shù)據(jù)庫(kù).* to 用戶(hù)名@登錄主機(jī) identified by "密碼"
例1、增加一個(gè)用戶(hù)user001密碼為123456,讓他可以在任何主機(jī)上登錄,并對(duì)所有數(shù)據(jù)庫(kù)有查詢(xún)、插入、修改、刪除的權(quán)限。首先用以root用戶(hù)連入MySQL,然后鍵入以下命令:
mysql > grant select,insert,update,deleteon*.*touser001@"%" Identifiedby"123456";
例2、增加一個(gè)用戶(hù)user002密碼為123456,讓此用戶(hù)只可以在localhost上登錄,也可以設(shè)置指定IP,并可以對(duì)數(shù)據(jù)庫(kù)test進(jìn)行查詢(xún)、插入、修改、刪除的操作 (localhost指本地主機(jī),即MySQL數(shù)據(jù)庫(kù)所在的那臺(tái)主機(jī))
//這樣用戶(hù)即使用知道user_2的密碼,他也無(wú)法從網(wǎng)上直接訪問(wèn)數(shù)據(jù)庫(kù),只能通過(guò)MYSQL主機(jī)來(lái)操作test庫(kù)。
//首先用以root用戶(hù)連入MySQL,然后鍵入以下命令:
mysql>grant select,insert,update,deleteontest.*touser002@localhostidentifiedby"123456";
原文鏈接www.cnblogs.com/xdpxyxy/archive/2012/11/16/2773662.html,侵權(quán)聯(lián)系刪除
修改同時(shí)多個(gè)數(shù)據(jù),用‘,’隔開(kāi)。