国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

mysql命令行腳本執(zhí)行操作示例

2020-01-18 20:39:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了mysql命令行腳本執(zhí)行操作。分享給大家供大家參考,具體如下:

命令行連接

在工作中主要使用命令操作方式,要求熟練編寫

打開(kāi)終端,運(yùn)行命令

mysql -uroot -p

回車后輸入密碼,當(dāng)前設(shè)置的密碼為mysql

連接成功后如下圖

退出登錄

quit 和 exit

ctrl+d

登錄成功后,輸入如下命令查看效果

查看版本:select version();

顯示當(dāng)前時(shí)間:select now();

修改輸入提示符

prompt python>1/D 完整日期/U 使用用戶

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

查看所有數(shù)據(jù)庫(kù)

show databases;

使用數(shù)據(jù)庫(kù)

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

查看當(dāng)前使用的數(shù)據(jù)庫(kù)

select database();

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

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

例:

create database python charset=utf8;

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

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

例:

drop database python;

數(shù)據(jù)表

查看當(dāng)前數(shù)據(jù)庫(kù)中所有表

show tables;

創(chuàng)建表

auto_increment表示自動(dòng)增長(zhǎng)

CREATE TABLE table_name(  column1 datatype contrai,  column2 datatype,  column3 datatype,  .....  columnN datatype,  PRIMARY KEY(one or more columns));

例:創(chuàng)建班級(jí)表

create table classes(  id int unsigned auto_increment primary key not null,  name varchar(10));

例:創(chuàng)建學(xué)生表

create table students(  id int unsigned primary key auto_increment not null,  name varchar(20) default '',  age tinyint unsigned default 0,  height decimal(5,2),  gender enum('男','女','人妖','保密'),  cls_id int unsigned default 0)

修改表-添加字段

alter table 表名 add 列名 類型;

例:

alter table students add birthday datetime;

修改表-修改字段:重命名版

alter table 表名 change 原名 新名 類型及約束;

例:

alter table students change birthday birth datetime not null;

修改表-修改字段:不重命名版

alter table 表名 modify 列名 類型及約束;

例:

alter table students modify birth date not null;

修改表-刪除字段

alter table 表名 drop 列名;

例:

alter table students drop birthday;

刪除表

drop table 表名;

例:

drop table students;

查看表的創(chuàng)建語(yǔ)句

show create table 表名;

例:

show create table classes;

增刪改查(curd)

curd的解釋: 代表創(chuàng)建(Create)、更新(Update)、讀取(Retrieve)和刪除(Delete)

查詢基本使用

查詢所有列

select * from 表名;

例:

select * from classes;

查詢指定列

可以使用as為列或表指定別名

select 列1,列2,... from 表名;

例:

select id,name from classes;

增加

格式:INSERT [INTO] tb_name [(col_name,…)] {VALUES | VALUE} ({expr | DEFAULT},…),(…),…

說(shuō)明:主鍵列是自動(dòng)增長(zhǎng),但是在全列插入時(shí)需要占位,通常使用0或者 default 或者 null 來(lái)占位,插入成功后以實(shí)際數(shù)據(jù)為準(zhǔn)

全列插入:值的順序與表中字段的順序?qū)?yīng)

insert into 表名 values(...)

例:

insert into students values(0,'郭靖‘,1,'蒙古','2016-1-2');

部分列插入:值的順序與給出的列順序?qū)?yīng)

insert into 表名(列1,...) values(值1,...)

例:

insert into students(name,hometown,birthday) values('黃蓉','桃花島','2016-3-2');

上面的語(yǔ)句一次可以向表中插入一行數(shù)據(jù),還可以一次性插入多行數(shù)據(jù),這樣可以減少與數(shù)據(jù)庫(kù)的通信

全列多行插入:值的順序與給出的列順序?qū)?yīng)

insert into 表名 values(...),(...)...;

例:

insert into classes values(0,'python1'),(0,'python2');
insert into 表名(列1,...) values(值1,...),(值1,...)...;

例:

insert into students(name) values('楊康'),('楊過(guò)'),('小龍女');

修改

格式: UPDATE tbname SET col1={expr1|DEFAULT} [,col2={expr2|default}]…[where 條件判斷]

update 表名 set 列1=值1,列2=值2... where 條件

例:

update students set gender=0,hometown='北京' where id=5;

刪除

DELETE FROM tbname [where 條件判斷]
delete from 表名 where 條件

例:

delete from students where id=5;

邏輯刪除,本質(zhì)就是修改操作

update students set isdelete=1 where id=1;

備份

運(yùn)行mysqldump命令

mysqldump 

主站蜘蛛池模板:
射洪县|
遵义市|
修武县|
靖宇县|
富民县|
衡南县|
神木县|
留坝县|
盘山县|
伊宁市|
滁州市|
郎溪县|
江都市|
南平市|
磴口县|
富民县|
石阡县|
河南省|
改则县|
应城市|
肥东县|
曲周县|
衡水市|
天水市|
芒康县|
栾川县|
辰溪县|
察哈|
青海省|
莱州市|
铜山县|
三都|
永兴县|
宜州市|
南充市|
体育|
天水市|
红桥区|
余江县|
林口县|
镇原县|