MySQL基礎筆記

2021-07-26 13:46:27 字數 1530 閱讀 3352

連線資料庫: 一般都是乙個api函式(不同語言不同,但引數相似)***_connect( server,user,passwd,newlink,clientflag);

建立與刪除乙個資料庫 在php是使用mysql_query(sql:是sql的查詢命令,connection:可選為sql識別符號)

選擇資料庫:mysql_select_db(dbname:資料名,connection:可選規定mysql連線)

mysql的資料型別有 1,2,3,4,8,位元組的整型,還有浮點,雙精型。

建立資料表 creat table tablename(colum_name :屬性名 column_type:屬性型別);

刪除資料表 drop table tablename;

插入資料: insert into table_name(field1,field2,field2 ....)values(value1 ,value2,value,「value3」」)value就是資料的值。

查詢資料: select column_name,column_name from tablename [where clause][offset m][limit n]

where語句:

mysql like語句:在使用select時

where 子句中可以使用等號 (=) 來設定獲取資料的條件,如 "runoob_author = 'sanjay'"。

但是有時候我們需要獲取 runoob_author 字段含有 "jay" 字元的所有記錄,這時我們就需要在 where 子句中使用 sql like 子句。

sql like 子句中使用百分號(%)字元來表示任意字元,類似於unix或正規表示式中的星號 (*)。

如果沒有使用百分號(%), like 子句與等號(=)的效果是一樣的。

例:select field1,field2,....fieldn table_name1,table_name2.... where field1 like condition1 [and [or]] field2 = "someone"

例如:select * from tablea where name = 「xy」

修改或者更新資料庫中的資料使用update來操作

update查詢: update table_name set field1 = new- value1,field2 = new -value2 [where clause] 

delete語句從資料表中刪除資料

delete from table_name[ where clause]

排序 使用order by字句啦設定想按那個字段那種方式進行排序,在返回搜尋結果。select field ,field2,...from tablename1,tablename2, order by field1,field2 ..[asc or desc]

分組:使用 group by  :select column column_name,functuon

注意:access不支援truncate語句 要刪除只能用delete 所以要刪除全部只能就把表刪了再建

mysql基礎筆記

1.建立資料庫 create database 資料庫名 create database if not exists 資料庫名 character set 編碼表 判斷是否有此資料庫,沒有就建立並指定編碼 2.查詢資料庫 show create database 資料庫名 查編碼 show data...

MySQL基礎筆記

注釋 1 空格 2 3 顯示所有資料庫 show databases 建立資料庫 create database 資料庫名 create database home 切換資料庫 use 資料庫名 use home use one 展示當前資料庫的所有表 show tables show tables...

mysql基礎筆記

型別 占用位元組數 範圍 2n 2n 1 1 n表示位數,一位元組 8位,儲存正整數時翻倍 tinyint 1 8位 128 127 28 1 28 1 1 0 224 int4 10位數,自己算吧 char m m,不夠m空格補 固定長度 varchar m m 1 m 2 字串裡是字元的概念,字...