99久久99久久精品免观看,国产精品久久久久国产精品,国产黄色录像视频,免费的黄色毛片,国产一区精品普通话对白,色妞妞成人在线观看,最新aⅴ福利在线观看免费

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

綠色資源網(wǎng)

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

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

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

常用的MySQL命令大全

一、連接MySQL
格式: mysql -h主機地址 -u用戶名 -p用戶密碼
1、例1:連接到本機上的MYSQL。
首先在打開DOS窗口,然后進入目錄 mysqlbin,再鍵入命令mysql -uroot -p,回車后提示你輸密碼,如果剛安裝好MYSQL,超級用戶root是沒有密碼的,故直接回車即可進入到MYSQL中了,MYSQL的提示符是: mysql>。
2、例2:連接到遠程主機上的MYSQL。假設遠程主機的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加個密碼ab12。首先在DOS下進入目錄mysqlbin,然后鍵入以下命令:
mysqladmin -uroot -password ab12
注:因為開始時root沒有密碼,所以-p舊密碼一項就可以省略了。
2、例2:再將root的密碼改為djg345。
mysqladmin -uroot -pab12 password djg345
 

增加新用

三、增加新用戶。(注意:和上面不同,下面的因為是MySQL環(huán)境中的命令,所以后面都帶一個分號作為命令結束符)
格式:grant select on 數(shù)據(jù)庫.* to 用戶名@登錄主機 identified by \"密碼\"
例1、增加一個用戶test1密碼為abc,讓他可以在任何主機上登錄,并對所有數(shù)據(jù)庫有查詢、插入、修改、刪除的權限。首先用以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中有關數(shù)據(jù)庫方面的操作。注意:你必須首先登錄到MySQL中,以下操作都是在MySQL的提示符下進行的,而且每個命令以分號結束。
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)建一個可以從任何地方連接服務器的一個完全的超級用戶,但是必須使用一個口令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;
刪除授權:
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

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

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

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

閱讀本文后您有什么感想? 已有 人給出評價!

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