這幾天學習了資料庫(MySQL)的相關操作
這篇博客總結一下資料庫的最最基本的操作
首先在搭建環境的條件下 啟用資料庫
首先新建一個資料庫 名為student
使用命令create database student;
如果在這前創建過資料庫并且重名的話就會產生報錯
這樣我們可以通過show database來查看所有之前創建的資料庫

然后可以使用**drop database student;**來洗掉之前的資料庫

洗掉之后即可創建想要的資料庫
然后我們要使用我們剛剛創建的資料庫 使用 use student;

然后我們可以查看此資料庫中的表
使用show tables;

這里因為沒有創建表 所以是空的
我們創建一個表 里邊有id name sex
create table student_info (id int,name varchar(4),sex varchar(4));
然后通過desc student_info可查看表中資料

可以看到我們創建的id name sex
然后我們向表中添加資料
使用insert into student_info values(01,‘小明’,‘男’);
然后出現成功的指令

我們就像這樣多添加幾個角色
然后通過**select*from student_info order by id;**即可查看我們添加的所有資料
而且是通過id來排序的(也可以通過其他)

接下來我們嘗試修改資料庫表中的資料
通過update student_info set name=‘小花’ where id=2;
其中的set是修改之后的值 where是查找相匹配字符

然后我們洗掉一些資訊
delete from student_info where id=2;
就是查找id=2的進行洗掉

然后我們可以查找條件的全部資訊
這里我通過性別來查詢
select id ,name from stduent_info where seks=‘男’;

然后我們添加一個欄位
alter table student_info add phone int(11);
然后查看

很明顯多了phone一欄
然后我們嘗試修改欄位名稱
alter table student_info change id later_id int;

然后我們洗掉欄位
alter table student_info drop column phone;

然后我們可以查看所有的表
show tables

大致就這么多 這篇博客介紹了MySQL的最基本的用法
希望對大家有用
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/223063.html
標籤:python
