日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql全表重命名备份_Mysql数据库和表的常用操作以及数据备份恢复

發(fā)布時間:2023/12/19 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql全表重命名备份_Mysql数据库和表的常用操作以及数据备份恢复 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

數(shù)據(jù)庫

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

show databases;

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

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

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

select database();

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

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

例:

create database python charset=utf8;

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

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

例:

drop database python;

數(shù)據(jù)表

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

show tables;

查看表結(jié)構(gòu)

desc 表名;

創(chuàng)建表

auto_increment表示自動增長

CREATE TABLE table_name(

column1 datatype contrai,

column2 datatype,

column3 datatype,

.....

columnN datatype,

PRIMARY KEY(one or more columns)

);

例:創(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

)

修改表-添加字段

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)建語句

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},...),(...),...

說明:主鍵列是自動增長,但是在全列插入時需要占位,通常使用0或者 default 或者 null 來占位,插入成功后以實(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');

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

全列多行插入:值的順序與給出的列順序?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('楊康'),('楊過'),('小龍女');

修改

格式: UPDATE tbnameSET 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 –uroot –p 數(shù)據(jù)庫名 > python.sql;

?

# 按提示輸入mysql的密碼

恢復(fù)

連接mysql,創(chuàng)建新的數(shù)據(jù)庫

退出連接,執(zhí)行如下命令

mysql -uroot –p 新數(shù)據(jù)庫名 < python.sql

?

# 根據(jù)提示輸入mysql密碼

總結(jié)

以上是生活随笔為你收集整理的mysql全表重命名备份_Mysql数据库和表的常用操作以及数据备份恢复的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。