www.国产视频,一级看片免费视频囗交动图,波多野结衣高清无码中文456,中国一级特黄特级毛片,69mmWWW路cOm,天天摸夜夜摸黄片,aaaaaaaaa在线观看

綠色資源網(wǎng):您身邊最放心的安全下載站! 最新軟件|熱門排行|軟件分類|軟件專題|論壇轉(zhuǎn)帖|廠商大全

綠色資源網(wǎng)

技術(shù)教程
您的位置:首頁(yè)數(shù)據(jù)庫(kù)類MySQL → 常用的MySQL數(shù)據(jù)庫(kù)命令大全

常用的MySQL數(shù)據(jù)庫(kù)命令大全

我要評(píng)論 2011/12/25 15:05:47 來(lái)源:綠色資源網(wǎng) 編輯:downcc.com [ ] 評(píng)論:0 點(diǎn)擊:297次

常用的MySQL命令大全

一、連接MySQL
格式: mysql -h主機(jī)地址 -u用戶名 -p用戶密碼
1、例1:連接到本機(jī)上的MYSQL。
首先在打開DOS窗口,然后進(jìn)入目錄 mysqlbin,再鍵入命令mysql -uroot -p,回車后提示你輸密碼,如果剛安裝好MYSQL,超級(jí)用戶root是沒(méi)有密碼的,故直接回車即可進(jìn)入到MYSQL中了,MYSQL的提示符是: mysql>。
2、例2:連接到遠(yuǎn)程主機(jī)上的MYSQL。假設(shè)遠(yuǎn)程主機(jī)的IP為:110.110.110.110,用戶名為root,密碼為abcd123。則鍵入以下命令:
mysql -h110.110.110.110 -uroot -pabcd123
(注:u與root可以不用加空格,其它也一樣)
3、退出MYSQL命令: exit (回車)。

修改mYSQL 管理員密碼

二、修改密碼
格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼
1、例1:給root加個(gè)密碼ab12。首先在DOS下進(jìn)入目錄mysqlbin,然后鍵入以下命令:
mysqladmin -uroot -password ab12
注:因?yàn)殚_始時(shí)root沒(méi)有密碼,所以-p舊密碼一項(xiàng)就可以省略了。
2、例2:再將root的密碼改為djg345。
mysqladmin -uroot -pab12 password djg345
 

增加新用

三、增加新用戶。(注意:和上面不同,下面的因?yàn)槭荕ySQL環(huán)境中的命令,所以后面都帶一個(gè)分號(hào)作為命令結(jié)束符)
格式:grant select on 數(shù)據(jù)庫(kù).* to 用戶名@登錄主機(jī) identified by \"密碼\"
例1、增加一個(gè)用戶test1密碼為abc,讓他可以在任何主機(jī)上登錄,并對(duì)所有數(shù)據(jù)庫(kù)有查詢、插入、修改、刪除的權(quán)限。首先用以root用戶連入MySQL,然后鍵入以下命令:
grant select,insert,update,
delete on *.* to test2@localhost identified by \"abc\";
如果你不想test2有密碼,可以再打一個(gè)命令將密碼消掉。
grant select,insert,update,delete on mydb
.* to test2@localhost identified by \"\";
在上面講了登錄、增加用戶、密碼更改等問(wèn)題。下面我們來(lái)看看MySQL中有關(guān)數(shù)據(jù)庫(kù)方面的操作。注意:你必須首先登錄到MySQL中,以下操作都是在MySQL的提示符下進(jìn)行的,而且每個(gè)命令以分號(hào)結(jié)束。
1、MySQL常用命令
create database name; 創(chuàng)建數(shù)據(jù)庫(kù)
use databasename; 選擇數(shù)據(jù)庫(kù)
drop database name 直接刪除數(shù)據(jù)庫(kù),不提醒
show tables; 顯示表
describe tablename; 表的詳細(xì)描述
select 中加上distinct去除重復(fù)字段
mysqladmin drop database name 刪除數(shù)據(jù)庫(kù)前,有提示。
顯示當(dāng)前mysql版本和當(dāng)前日期
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ù)庫(kù)
mysql>use dbname; 打開數(shù)據(jù)庫(kù):
mysql>show databases; 顯示所有數(shù)據(jù)庫(kù)
mysql>show tables; 顯示數(shù)據(jù)庫(kù)mysql中所有的表:先use mysql;然后
mysql>describe user; 顯示表mysql數(shù)據(jù)庫(kù)中user表的列信息);
3、grant
創(chuàng)建一個(gè)可以從任何地方連接服務(wù)器的一個(gè)完全的超級(jí)用戶,但是必須使用一個(gè)口令something做這個(gè)
mysql> grant all privileges on *.* to user@localhost identified by ’something’ with
增加新用戶
格式:grant select on 數(shù)據(jù)庫(kù).* to 用戶名@登錄主機(jī) 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)建一個(gè)用戶custom在特定客戶端it363.com登錄,可訪問(wèn)特定數(shù)據(jù)庫(kù)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

恢復(fù)、備份數(shù)據(jù)庫(kù)

備份數(shù)據(jù)庫(kù)
shell> mysqldump -h host -u root -p dbname >dbname_backup.sql
恢復(fù)數(shù)據(jù)庫(kù)
shell> mysqladmin -h myhost -u root -p create dbname
shell> mysqldump -h host -u root -p dbname < dbname_backup.sql
如果只想卸出建表指令,則命令如下:
shell> mysqladmin -u root -p -d databasename > a.sql
如果只想卸出插入數(shù)據(jù)的sql命令,而不需要建表命令,則命令如下:
shell> mysqladmin -u root -p -t databasename > a.sql
那么如果我只想要數(shù)據(jù),而不想要什么sql命令時(shí),應(yīng)該如何操作呢?
   mysqldump -T./ phptest driver
其中,只有指定了-T參數(shù)才可以卸出純文本文件,表示卸出數(shù)據(jù)的目錄,./表示當(dāng)前目錄,即與mysqldump同一目錄。如果不指定driver 表,則將卸出整個(gè)數(shù)據(jù)庫(kù)的數(shù)據(jù)。每個(gè)表會(huì)生成兩個(gè)文件,一個(gè)為.sql文件,包含建表執(zhí)行。另一個(gè)為.txt文件,只包含數(shù)據(jù),且沒(méi)有sql指令。
5、可將查詢存儲(chǔ)在一個(gè)文件中并告訴mysql從文件中讀取查詢而不是等待鍵盤輸入??衫猛鈿こ绦蜴I入重定向?qū)嵱贸绦騺?lái)完成這項(xiàng)工作。例如,如果在文件my_file.sql 中存放有查
詢,可如下執(zhí)行這些查詢:
例如,如果您想將建表語(yǔ)句提前寫在sql.txt中:
mysql > mysql -h myhost -u root -p database < sql.txt
1、安裝環(huán)境:
Windows XP
Mysql 4.0.17 從 下次就需要用mysql -uroot -proot才可以登陸
在遠(yuǎn)程或本機(jī)可以使用 mysql -h 172.5.1.183 -uroot 登陸,這個(gè)根據(jù)第二行的策略確定
權(quán)限修改生效:
1)net stop mysql
net start mysql
2)c:\mysql\bin\mysqladmin flush-privileges
3)登陸mysql后,用flush privileges語(yǔ)句
6、創(chuàng)建數(shù)據(jù)庫(kù)staffer
create database staffer;
7、下面的語(yǔ)句在mysql環(huán)境在執(zhí)行
顯示用戶擁有權(quán)限的數(shù)據(jù)庫(kù) show databases;
切換到staffer數(shù)據(jù)庫(kù) use staffer;
顯示當(dāng)前數(shù)據(jù)庫(kù)中有權(quán)限的表 show tables;
顯示表staffer的結(jié)構(gòu) desc staffer;
8、創(chuàng)建測(cè)試環(huán)境
1)創(chuàng)建數(shù)據(jù)庫(kù)staffer
mysql> create database staffer
2)創(chuàng)建表staffer,department,position,depart_pos
create table s_position
(
id int not null auto_increment,
name varchar(20) not null default '經(jīng)理', #設(shè)定默認(rèn)值
description varchar(100),
primary key PK_positon (id) #設(shè)定主鍵
);
create table department
(
id int not null auto_increment,
name varchar(20) not null default '系統(tǒng)部', #設(shè)定默認(rèn)值
description varchar(100),
primary key PK_department (id) #設(shè)定主鍵
);
create table depart_pos
(
department_id int not null,
position_id int not null,
primary key PK_depart_pos (department_id,position_id) #設(shè)定復(fù)和主鍵
);
create table staffer
(
id int not null auto_increment primary key, #設(shè)定主鍵
name varchar(20) not null default '無(wú)名氏', #設(shè)定默認(rèn)值
department_id int not null,
position_id int not null,
unique (department_id,position_id) #設(shè)定唯一值
);
3)刪除
mysql>
drop table depart_pos;
drop table department;
drop table s_position;
drop table staffer;
drop database staffer;
9、修改結(jié)構(gòu)
mysql>
#表position增加列test
alter table position add(test char(10));
#表position修改列test
alter table position modify test char(20) not null;
#表position修改列test默認(rèn)值
alter table position alter test set default 'system';
#表position去掉test默認(rèn)值
alter table position alter test drop default;
#表position去掉列test
alter table position drop column test;
#表depart_pos刪除主鍵
alter table depart_pos drop primary key;
#表depart_pos增加主鍵
alter table depart_pos add primary key PK_depart_pos (department_id,position_id);

操作數(shù)據(jù)

10、操作數(shù)據(jù)
#插入表department
insert into department(name,description) values('系統(tǒng)部','系統(tǒng)部');
insert into department(name,description) values('公關(guān)部','公關(guān)部');
insert into department(name,description) values('客服部','客服部');
insert into department(name,description) values('財(cái)務(wù)部','財(cái)務(wù)部');
insert into department(name,description)

關(guān)鍵詞:MySQL,數(shù)據(jù)庫(kù),MySQL數(shù)據(jù)庫(kù)命令

閱讀本文后您有什么感想? 已有 人給出評(píng)價(jià)!

  • 1 歡迎喜歡
  • 1 白癡
  • 1 拜托
  • 1 哇
  • 1 加油
  • 1 鄙視