mysql 深胡 mysql 21 條基本命令

2021-10-18 21:20:19 字數 1714 閱讀 8457

1 . 檢視mysql版本資訊

mysqladmin --version

2 . 在mysql裡執行可顯示出當前伺服器版本。

select vertion();

3 . 輸入密碼即可連線到資料庫

mysql -u root -p

4 . 檢查mysql伺服器是否啟動,啟動就會有mysql的程序列表

ps -ef | grep mysqld

5 . 新建乙個資料庫。

create database t1;

6 . 顯示所有資料庫。

show databases;

7 . 刪除資料庫。

drop database t1;

8 . 選擇資料庫

use t1;

9 . 修改root使用者密碼。

mysqladmin -u root -p password 新密碼

10 . 選擇資料庫後建立資料表

create table user( *** char(4) not null);

***是列名,char(4)是列的資料型別,not null說明剛列的型別不能為空,預設的話是可以為空。

注意:至少要有一項

11 . 顯示資料庫表

show tables;

12 . 檢視資料庫表詳細資訊

describe 表名;

13 . 向表中插入資料

插入的是表中的列的值。

insert into student values("chen","male","135");

插入部分 表名後面+(列名)再加值。

insert into student(na) values("pan");

14 . 查詢表中資料

查詢表student中的所有列為***的值。

select *** from student;

*表示查詢所有內容。

select * from student;

按特定條件查詢,比如說查詢*** = ma。

select * from student where ***="ma";

查詢年齡大於50的

select * from student where age > 50;

查詢id小於5且年齡大於20的所有人資訊:

select * from students where id<5 and age>20;

15 . 更改表中資料

update 表名稱 set 列名稱=新值 where 更新條件;

upadate student set tel = 110 where na = "pan";

16 . 刪除表的資料

delete from 表名稱 where 刪除條件;

delete from student where tel = "110";

刪除表中所有資料

delete from student;

17 . 新增列

alter table 表名 add 列名 列資料型別;

18 . 修改列

alter table 表名 change 列名稱 列新名稱 新資料型別;

19 . 刪除列

alter table 表名 drop 列名稱;

20 . 重新命名表

alter table 表名 rename 新錶名;

21 . 刪除整張表

drop tabel 表名;

MySQL效能優化的21條最佳經驗

多數的mysql伺服器都開啟了查詢快取。這是提高性最有效的方法之一,而且這是被mysql的資料庫引擎處理的。當有很多相同的查詢被執行了多次的時候,這些查詢結果會被放到乙個快取中,這樣,後續的相同的查詢就不用操作表而直接訪問快取結果了。今天,資料庫的操作越來越成為整個應用的效能瓶頸了,這點對於web應...

MySQL效能優化的最佳21條經驗(下)

11.盡可能的使用 not null 除非你有乙個很特別的原因去使用 null 值,你應該總是讓你的字段保持 not null。這看起來好像有點爭議,請往下看。首先,問問你自己 empty 和 null 有多大的區別 如果是int,那就是0和null 如果你覺得它們之間沒有什麼區別,那麼你就不要使用...

mysql 森胡 Mysql(一)資料型別

優秀文章,第一時間收到!ksknowledge sharing 知識分享 現在是資源共享的時代,同樣也是知識分享的時代,如果你覺得從本文能學到知識,請把知識與別人分享。1.整數型別 1 指定型別顯示寬度 資料型別 顯示寬度 如 int 4 2 zerofilll屬性 用於資料不足的顯示空間由0來填補...