Mysql数据库和表的增删改查以及数据备份恢复
生活随笔
收集整理的這篇文章主要介紹了
Mysql数据库和表的增删改查以及数据备份恢复
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
數(shù)據(jù)庫
- 查看所有數(shù)據(jù)庫
- 使用數(shù)據(jù)庫
- 查看當(dāng)前使用的數(shù)據(jù)庫
- 創(chuàng)建數(shù)據(jù)庫
- 刪除數(shù)據(jù)庫
數(shù)據(jù)表
- 查看當(dāng)前數(shù)據(jù)庫中所有表
- 查看表結(jié)構(gòu)
- 創(chuàng)建表
- auto_increment表示自動增長
例:創(chuàng)建班級表
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 )- 修改表-添加字段
- 修改表-修改字段:重命名版
- 修改表-修改字段:不重命名版
- 修改表-刪除字段
- 刪除表
- 查看表的創(chuàng)建語句
增刪改查(curd)
curd的解釋: 代表創(chuàng)建(Create)、更新(Update)、讀取(Retrieve)和刪除(Delete)
查詢基本使用
- 查詢所有列
- 查詢指定列
- 可以使用as為列或表指定別名
增加
格式:INSERT [INTO] tb_name [(col_name,...)] {VALUES | VALUE} ({expr | DEFAULT},...),(...),...
- 說明:主鍵列是自動增長,但是在全列插入時需要占位,通常使用0或者 default 或者 null 來占位,插入成功后以實際數(shù)據(jù)為準(zhǔn)
- 全列插入:值的順序與表中字段的順序?qū)?yīng)
- 部分列插入:值的順序與給出的列順序?qū)?yīng)
- 上面的語句一次可以向表中插入一行數(shù)據(jù),還可以一次性插入多行數(shù)據(jù),這樣可以減少與數(shù)據(jù)庫的通信
- 全列多行插入:值的順序與給出的列順序?qū)?yīng)
?
修改
格式:?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ì)就是修改操作
備份
- 運行mysqldump命令
恢復(fù)
- 連接mysql,創(chuàng)建新的數(shù)據(jù)庫
- 退出連接,執(zhí)行如下命令
轉(zhuǎn)載于:https://www.cnblogs.com/fusheng11711/p/10773324.html
總結(jié)
以上是生活随笔為你收集整理的Mysql数据库和表的增删改查以及数据备份恢复的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jmeter问题
- 下一篇: linux cmake编译源码,linu