mysql 操作下標 mysql 各項操作流程

2021-10-17 18:18:20 字數 3542 閱讀 3237

啟動mysql:進入命令列輸入:net start mysql 如果失敗則顯示:服務名無效,需跳轉到指定bin目錄下進行啟動mysql,

登陸成功後則可以進行資料庫各種操作;

the end:操作完成後需要退出則:exit  即退出mysql

1:建立資料庫

1.1:show databases;

此命令檢視所有資料庫。

1.2:create database databasename;

建立乙個名為databasename的資料庫;

2:刪除資料庫

2.1:drop database databasename;

刪除乙個名為databasename的資料庫;

2.2:drop database if exists databasename;

刪除乙個不確定是否存在的名為databasename的資料庫,無論存在與否不報錯。

3:跳轉到指定資料庫(選擇資料庫)

use databasename;

跳轉到乙個名為databasename的資料庫。

成功則database changed

跳轉過後無需回到主介面,使用其他資料庫則直接 use anotherdatabasename即可

4:當前選定的資料庫

select database();

顯示當前選中的資料庫

select version();

顯示當前資料庫版本

select new();

顯示當前時間

5:建立資料表(table)

create table tablename(              //建立名為tablename的資料表

id int(4) not null primary key auto_increment,   //增加id屬性 性質為int  長度為4  不能為空 主鍵  預設值

name char(20) not null,    //增加name屬性  性質為char 長度20 .....

gender char(20) not null,    //增加gender屬性....

age int(4) not null,         //增加age屬性.....

power double not null default '0.00');   //增加power屬性  性質為double  不為空 主鍵為null 預設值為0.00

6:顯示表結構

desc tablename

顯示乙個名為tablename的表的結構

ex.6:修改表結構

新增表字段結構:alter table tablename add username varchar(40);//最後的屬性必須為全稱!!!

刪除表字段結構:alter table tablename drop username;

刪除表名為tablename資料表的username屬性列表

alter table tablename rename oldname to newname;

修改資料表tablename中oldname名字為新名字newname;

更改資料表屬性的性質和名字

alter table tablename change gender newgender character(40);

7:刪除資料表

drop table tablename

刪除乙個名為tablename的表

8:為資料表新增資料

insert into tablename values(1,'yihao','nv',17,100.00);

//新增到名為tablename的資料表中 1,yihao,nv,17,100.00 若干個資料

insertinto tablename values(2,'erhao','nv',17,99.00),(3,'sanhao','nv',19,99.99);

可以在第乙個資料後面加,後進行再次新增若干個資料節

9:查詢表中資料

select * from tablename

查詢乙個名為tablename表中的所有資料

select * from tablename where age=17;

查詢乙個名為tablename表中age為17的資料;

select * from tablename where power>=99;

查詢乙個名為tablename表中power大於等於99的資料;

select * from tablename where power between 99 and 100;

查詢乙個名為tablename表中power在 99《= x 》=100區間中的資料

select * from tablename where age like '%17%';

查詢乙個名為tablename表中age中擁有欄位17的資料;

select * from tablename where age is not null;

查詢乙個名為tablename表中age非空的資料;

select * from tablename order by id limit 0,3;

查詢乙個名為tablename表中前三行id的數值,前為下標後為長度

select * from tablename order by power asc;

查詢乙個名為tablename表中所有order資料並且公升序排列,從小到大

select * from tablename order by power desc;

查詢乙個名為tablename表中所有order資料並且降序排列,從大到小

select count(*) as '3' from tablename;

查詢名為tablename資料表中的資料總量

select id from tablename;

根據id查詢tablename中的資料

select distinct id from tablename;

在tablename資料表中查詢不同的id值資料

select id sd tableid from tablename;

查詢tablename資料表中的id值並將名稱顯示為tableid;

select id,name,gender,age+100 from tablename;

查詢tablename表中資料,顯示id、gender、age增加100後的值,且列表名同樣增加100(其會在上面清楚地顯示)

10:修改資料表名

rename table tablename to tablenameone;

降資料表tablename的名字修改為tablenameone;

11:刪除表中資料

delete from tablename where (id=1);//括號內為判斷表示式

刪除乙個名為tablename資料表中id為1的資料

12:修改表中資料

update tablename set name='frist' where id=1;

修改表名為tablename中id為1的資料,將其name值修改為first;

MySQL各儲存引擎

mysql中的資料用各種不同的技術儲存在檔案 或者記憶體 中。這些技術中的每一種技術都使用不同的儲存機制 索引技巧 鎖定水平並且最終提供廣泛的不同的功能和能力。通過選擇不同的技術,你能夠獲得額外的速度或者功能,從而改善你的應用的整體功能。這些不同的技術以及配套的相關功能在mysql中被稱作儲存引擎 ...

MySQL各儲存引擎

mysql中的資料用各種不同的技術儲存在檔案 或者記憶體 中。這些技術中的每一種技術都使用不同的儲存機制 索引技巧 鎖定水平並且最終提供廣泛的不同的功能和能力。通過選擇不同的技術,你能夠獲得額外的速度或者功能,從而改善你的應用的整體功能。這些不同的技術以及配套的相關功能在mysql中被稱作儲存引擎 ...

mysql各引擎優勢小記

選擇你的引擎 你能用的資料庫引擎取決於mysql在安裝的時候是如何被編譯的。要新增乙個新的引擎,就必須重新編譯mysql。僅僅為了新增乙個特性而編譯 應用程式的概念對於windows的開發人員來說可能很奇怪,但是在unix世界裡,這已經成為了標準。在預設情況下,mysql支援三個引 擎 isam m...