常用命令集合,linux常用命令
資料庫伺服器(很多庫)---庫(很多表)----表
//顯示所有的資料庫
mysql> show databases;
//建立一個新的資料庫
mysql> create database 資料庫名字;
//進入資料庫
mysql> use 資料庫名字; (顯示Database changed)
//顯示資料庫中的所有表(進入的庫中的表)
mysql> show tableS; (顯示Empty set (0.00 sec))
//建立一個新的表(進入的庫中建立)
mysql> create table PersonList(表名)
-> (
-> id int not null, (列名+類型+其他)
-> name char(8) not null,
-> title char(8)not null
-> );
//顯示表的結構
mysql> DESCRIBE mytable;
增:
//插入單行資料(順序插入)
mysql> insert into PersonList
-> values
-> (1,"呂布","奉先");
//插入多行資料(順序插入)
mysql> insert into PersonList
-> values
-> (5,"關羽","雲長"),(6,"張飛","益德");
//插入一行中的部分資料(順序插入)
mysql> insert into students (id, name, title) values(4,"孫策", "伯符");
//插入一列(在最後)
mysql> alter table PersonList add sex(插入的列名) char(8);
//在name列後插入tel列(記得新插入的列寫它的資料類型,我寫了好半天才發現)
mysql> alter table PersonList add tel char(8) after name;
查:
//查詢該表所有資料
mysql> select * from PersonList;(表名)
//按條件查詢(只顯示這個條件下的資料,例如查姓名只顯示每個人的姓名)
mysql> select name(條件,可以多個,逗號隔開) from PersonList(表名);
//查詢表中id>2的所有行資料
mysql> select * from PersonList where id >2;
//查詢表中姓名帶有“呂”字的資料
mysql> select * from PersonList where name like "%呂%";
//查詢表中id<6並且id>1的資料(可以運用and、or、=、!=、>=等)
mysql> select * from PersonList where id<6 and id>1;
改:
//將表中所有的id減1
mysql> update PersonList set id=id-1;
//將表中名字為呂布的id更改為-1(set是要更改的,where後是條件)
update PersonList set id=-1 where name = "呂布";
//將表中姓名為呂布,號為奉先的資料id更改為0(可以多個條件或者多個要修改的資料)
mysql> update PersonList set id=0 where title="奉先" and name="呂布";
//將表中列為title名字改為tit(如果title裡面的資料為空白,會一直報錯)
mysql> alter table PersonList change title tit char(5) not null;
//將表名PersonList改為Person
mysql> alter table PersonList rename Person;
刪:
//將表中id為1的正行資料刪掉
mysql> delete from PersonList where id=1;
//將表中所有資料刪除
mysql> delete from PersonList ;
//刪除tel這一列
mysql> alter table PersonList drop tel;
//刪除Person這張表
mysql> drop table Person;
//刪除資料庫threekinggenerallist
mysql> drop database threekinggenerallist;
最後: