4.数据库(增删改查)备份及恢复
查詢所有列 select * from 表名;
例:select * from classes;
查詢指定列,可以使用as為列或表指定別名
select 列1,列2,...from 表名;
例:select id,name from classes;
?
增加
全列插入:值的順序與表中字段的順序?qū)?/span>
insert into 表名values(...)
例:insert into students values(0,’郭靖‘,1,'蒙古','2016-1-2');
?
部分列插入:值的順序與給出的列順序?qū)?/span>
insert into 表名(列1,...)values(值1,...)
例:insert into students(name,hometown,birthday) values('黃蓉','桃花島','2016-3-2');
?
上面的語句一次可以向表中插入一行數(shù)據(jù),還可以一次性插入多行數(shù)據(jù),這樣可以減少與數(shù)據(jù)庫的通信
?
全列多行插入:值的順序與給出的列順序?qū)?/span>
insert into 表名values(...),(...)...;
例:insert into classes values(0,'python1'),(0,'python2');
insert into 表名(列1,...) values(值1,...),(值1,...)...;
例:insert into students(name) values('楊康'),('楊過'),('小龍女');
?
?
修改
update 表名 set列1=值1,列2=值2...where 條件
例:update students set gender=0,hometown='古墓' where id=5;
?
刪除
delete from 表名where 條件
例:delete from students where id=5;
?
邏輯刪除,本質(zhì)就是修改操作
邏輯刪除
對于重要數(shù)據(jù),并不希望物理刪除,一旦刪除,數(shù)據(jù)無法找回
刪除方案:設(shè)置isDelete的列,類型為bit,表示邏輯刪除,默認值為0
對于非重要數(shù)據(jù),可以進行物理刪除
數(shù)據(jù)的重要性,要根據(jù)實際開發(fā)決定
?
1.alter table add isdelete bit default 0;
2.update students set isdelete=1 where id=1;
?
備份
運行mysqldump命令
mysqldump –uroot –p 數(shù)據(jù)庫名 >python.sql;
# 按提示輸入mysql的密碼
恢復
連接mysql,創(chuàng)建新的數(shù)據(jù)庫
退出連接,執(zhí)行如下命令
mysql -uroot –p新數(shù)據(jù)庫名 < python.sql
# 根據(jù)提示輸入mysql密碼
總結(jié)
以上是生活随笔為你收集整理的4.数据库(增删改查)备份及恢复的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中的字符串操作及注意事项
- 下一篇: python-mysql超简单银行转账