自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

新手入門MySQL數(shù)據(jù)庫(kù)命令大全

數(shù)據(jù)庫(kù) MySQL
本文是為新手入門總結(jié)的MySQL數(shù)據(jù)庫(kù)命令大全,希望對(duì)大家有所幫助。

新手入門MYSQL數(shù)據(jù)庫(kù)命令大全

 一、命令行連接數(shù)據(jù)庫(kù)

Windows操作系統(tǒng)進(jìn)入CMD命令行,進(jìn)入mysql.exe所在目錄,運(yùn)行命令

mysql.exe -h主機(jī)名 -u用戶名 -p密碼

注意:參數(shù)名與值之間沒(méi)有空格 , 如:-h127.0.0.1

二、數(shù)據(jù)庫(kù)命令

1. 創(chuàng)建數(shù)據(jù)庫(kù)

create database 數(shù)據(jù)庫(kù)名;

如:

  1. create database itsource;

2. 切換到指定數(shù)據(jù)庫(kù)

use 數(shù)據(jù)庫(kù)名;

如:

  1. use itsource;

3. 顯示數(shù)據(jù)庫(kù)列表

  1. show databases;

4. 顯示數(shù)據(jù)庫(kù)建立語(yǔ)句

show create database 數(shù)據(jù)庫(kù)名;

如:

  1. show create database itsource;

5. 修改數(shù)據(jù)庫(kù)

alter database 數(shù)據(jù)庫(kù)名 選項(xiàng);

如:

  1. alter database itsource charset=gbk;

6. 刪除數(shù)據(jù)庫(kù)

drop database 數(shù)據(jù)庫(kù)名;

如:

  1. drop database itsource;

三、數(shù)據(jù)表命令

1. 創(chuàng)建數(shù)據(jù)表

create table 數(shù)據(jù)表名(

字段名1 類型 修飾符,

字段名2 類型 修飾符,

字段名n 類型 修飾符

);

如:

  1. create table news(
  2. id int primary key auto_increment,
  3. title varchar(50),
  4. author varchar(20),
  5. content text ); 

2. 查看數(shù)據(jù)表列表

  1. show tables;

3. 查看數(shù)據(jù)表結(jié)構(gòu)

desc 數(shù)據(jù)表名;

例如:

  1. desc news;

4. 查看數(shù)據(jù)表建表語(yǔ)句

show create table 數(shù)據(jù)表名;

如:

  1. show create table news;

5. 刪除數(shù)據(jù)表

drop table 數(shù)據(jù)表名;

如:

  1. drop table news;

6. 修改數(shù)據(jù)表

alter table 數(shù)據(jù)表名 選項(xiàng);

如:

  1. alter table news charset=utf8;

7. 新增字段

alter table 數(shù)據(jù)表名 add column 字段名 類型 修飾語(yǔ)句 位置

如:

  1. alter table news add column newstime timestamp default current_timestamp after content;

8. 修改字段定義

alter table 數(shù)據(jù)表名 modify column 字段名 新的定義

如:

  1. alter table news modify column content longtext;

9. 修改字段名及定義

alter table 數(shù)據(jù)表名 change column 舊字段名 新字段名 新的定義; 

10. 刪除字段

alter table 數(shù)據(jù)表名 drop column 字段名;

如:

  1. alter table news drop column title;

四、記錄操作命令

1. 新增記錄

insert into 數(shù)據(jù)表名(字段1,字段2,字段n) values(值1,值2,值n);

如:

  1. insert into news(title,author,content) values('新聞標(biāo)題','作者','新聞詳細(xì)內(nèi)容');

注意:值的數(shù)量與類型必須與字段列表數(shù)量與類型定義一致

2. 查看記錄

select 字段列表 from 數(shù)據(jù)表名 where 條件 order by 字段名 desc limit m,n

如:

  1. select * from news;
  2. select * from news where id=10;
  3. select * from news order by id desc limit 10; 

注意:select語(yǔ)句是SQL中最為強(qiáng)大與復(fù)雜的查詢語(yǔ)句,有七大子句,每段子句都可以省略,如果出現(xiàn)必須在正確的位置順序上,不可調(diào)換先后位置。

3. 修改記錄

update 數(shù)據(jù)表名 set 字段1=值1 and 字段2=值2 where 條件;

如:

  1. update news set title='新的新聞標(biāo)題' where id=1;

4. 刪除記錄

delete from 數(shù)據(jù)表名 where 條件;

如:

  1. delete from news where id=10;

五、其它常用命令

  1. set names gbk

由于CMD命令行只支持系統(tǒng)當(dāng)前編碼,所以一般需要將CMD與MYSQL服務(wù)器的交互編碼設(shè)置為gbk才能正常顯示utf8的數(shù)據(jù)。

【編輯推薦】

 

 

 

 

 

 

 

責(zé)任編輯:龐桂玉 來(lái)源: 今日頭條
相關(guān)推薦

2010-05-14 18:31:17

MySQL 定時(shí)數(shù)據(jù)備

2013-12-24 10:04:01

PostgreSQL

2010-11-03 15:24:36

DB2數(shù)據(jù)庫(kù)命令

2011-02-21 17:51:39

Zimbra入門新手

2010-05-28 18:22:51

MySQL基本操作

2010-05-25 09:40:01

MySQL數(shù)據(jù)庫(kù)

2011-01-10 14:36:00

新手linux基礎(chǔ)

2011-05-31 16:47:47

SEO

2010-06-10 10:31:36

MySQL出錯(cuò)代碼列表

2010-06-07 10:59:13

MySQL數(shù)據(jù)庫(kù)命令

2011-07-28 13:22:43

2010-09-09 13:40:19

XML DOM

2010-06-23 15:00:50

Fix協(xié)議

2011-03-22 11:06:52

Nagios安裝

2010-05-11 14:00:01

MySQL數(shù)據(jù)庫(kù)命令

2019-04-28 09:36:11

GitHub代碼開(kāi)發(fā)者

2010-05-25 14:42:14

MySQL 數(shù)據(jù)庫(kù)

2009-07-16 09:07:46

Linux使用技巧Linux入門Linux開(kāi)發(fā)

2010-05-17 09:52:55

虛擬化VMware Play

2010-06-21 15:27:38

Linux apt-g
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)