標籤:incr 表頭 help 根據 local 建立 quit 開啟 start
資料庫-MySql預設的超級管理員
使用者名稱:root
密碼:root
localhost 127.0.0.1 都表示本機
標識符
- PK:Primary Key (column is part of a pk) 主鍵
- NN:Not Null (column is nullable) 非空
- UQ:Unique (column is part of a unique key) 唯一
- B: Binary 二進位(比text更大的位元據)
- UN:Unsigned 整數
- ZF:Zero Fill 填充0,例如內容1 int(4),則顯示為0001。
AI:Auto Increment (the column is auto incremented when rows are inserted) 自增
建立資料庫在SCHEMAS中右鍵,點擊creat schemas。輸入資料庫名,選擇編碼格式:utf8mb4-default collation (支援中文)。
建立表可以再資料庫上右擊create table。
插入資料表設定主鍵,在查看錶時出現*就能插入資料,修改插入後點擊apply(mysql不分大小寫)
外部索引鍵關聯
在建表的頁面有一個Foreign Keys 可通過設定進行關聯
- Foreign key Name:自己隨便起個合適的名字
- Referenced Table:選擇資料庫
- 選擇對應列Column:當前表的列,R..Column:2中選擇的資料庫對應的列。
- 外鍵可以一對一,一對多,多對多。
使用MySql控制台
- 開啟MySql控制台(輸入密碼進入)
a.可以直接在開始菜單找到mysql控制台開啟
b.在mysql5.7檔案夾中找到拖入cmd中在其後輸入 -u使用者名稱 -p密碼
- 查看所有資料庫命令:show databases;
- 查看資料庫表格命令:1、use 資料庫名; 2、show tables;
- 建立資料庫命令:create database 資料庫名;
- 刪除資料庫命令:drop database 資料庫名;
- 協助命令:help;
- 退出命令:quit;
利用sql語句進行增刪改查
- use 想使用的資料庫
建立表
create table tablename( col_name type not null auto_increment,col_name type default,primary key(col_name
- 查看錶結構命令:desc 表名;
- 刪除表命令:drop 表名;
查看錶命令:show tables;
插入表
insert into tablename(col_name,col_name,col_name)values(value1,value2,value3);
- 查看錶所有資料命令:select * from 表名;
修改表
update tablename set col_name = value, col_name = value where condition; {條件,如果不加那麼會修改所有相同列名的資料}
刪除表資料
delete from tablename where condition; {如果不跟條件就會刪除所有資料}
尋找排序
- select * form 表名 limit 2;{查詢前兩條資料}
- select * form 表名 limit 2,3;{去掉前2條,從第三條往後查3條}
- select * form 列名 from 表名 where 條件;
- 例:select * from mytable order by id;{根據id進行排序}
- id後加desc 表示反序
!條件可以跟多個。 ex:
select * from mytable order by id,nsme desc;
查詢靜態值
select ‘some thing’; 查詢靜態記錄
select 1+1; 查詢結果
select now(); 取到當前的時間日期
as 修改表頭
select curdate(); 查詢當前的日期
select curtime(); 查詢當前的時間
select pi(); π的值
select mod(30,10); 求餘
select sqrt(24); 平方根
select round(x,y) 四捨五入保留y位小數
select floor(); 直接舍
- 可以去mysql官網找到所以有的函數functions and Operators
資料庫的備份和恢複
1、備份
點擊導覽列的Data Export-選擇資料庫-Export to Dump Project Folder 設定位置-start Export(打包出來的是每一個表一個檔案夾)
Export to Self-Contained File選擇位置-起檔案夾名(打包成單個檔案夾)
2、恢複
點擊導覽列 Data Import-恢複有兩種方式分別對應備份時的選擇-找到要匯入的資料庫-Default Target Schema(建立一個新的資料庫也可以選擇已經有的,來存放恢複的資料)-start import
推薦網站
w3school
本作品由A_AiTing採用知識共用署名-非商業性使用 4.0 國際許可協議進行許可。
MySQL的使用(上)