天天看點

MySQL學習筆記_1_MySQL資料庫管理系統概述

1、 MySQL架構

C/S: client / server架構

MySQL DBMS(Data Bank Management System): 資料庫管理系統

用戶端 <---> 伺服器 ---> 資料庫 ---> 資料表 ---> (記錄/行,字段/列)

MySQL學習筆記_1_MySQL資料庫管理系統概述

2、 資料庫程式員需要精通的操作:(不是DBA(資料庫管理者))

一、為項目設計表

二、使用SQL語句(SQL語句程式設計)

其他、都可以通過工具來完成。

3、MySQL檔案結構

  配置檔案:my.ini: 可以通過修改該檔案,來配置MySQL相應的屬性

bin檔案目錄: 儲存了MySQL所有的指令

data檔案目錄: 儲存了MySQL所包含的庫,各個庫裡面包含的是相應的 表!

【備份時,隻需将data檔案夾打包備份出去就可以了,Linux下為var/】

4、SQL語句操作

SQL(Structured Query Language)是一種進階的非過程化的語言。

SQL語句:結構簡單,功能強大,簡單易學!

按功能劃分:

DDL:建立資料庫,資料表的語句

DML:操作資料的語句

DQL:資料庫查詢語句

DCL:資料控制的語句,可以工具執行。

如: \s 檢視狀态

show databases; 檢視所有庫

show tables;  檢視所有表

desc tables; 檢視表結構

show variables; 檢視配置檔案中的變量

DDL: 1、執行SQL語句,首先要連接配接到資料庫伺服器上:

mysql -h localhost -u root -p #以root使用者登入到本地資料庫

\s:檢視資料庫狀态

show variables;:檢視系統中預設配置的變量,謹記:以;結束

show variables like 'time_zone';

show variables like 'port'; : 檢視端口

show databases; : 顯示系統中所有的庫

2、建立資料庫

create database [name];

如: create database boost;

3、删除資料庫

drop database [name];

如: drop datebase boost;

  拓展: cteate database if not exists boost;

drop database if exists boost;

4、建立一張資料表

create table boost.users(id int,name char(30),age int,sex char(3)); 

5、選擇一個庫作為預設資料庫

use boost;

6、檢視所有的表

show tables;

7、檢視表結構

desc users;

8、删除表

drop table users; // drop table if exists users;

9、繼續在預設資料庫中建立

create table users(id int,name char(32),age int,sex char(2));

拓展:

       create table is not exists users(id int,name char(32));

10、再建立一張表

create table is not exists articles(title char(64));

DML: 11、插入資料

insert into users values('2012','xiaofang','34','nan');

或:  insert into users values(2012,'xiaofang',34,'man'); //弱類型檢查

最佳實踐: insert into users(id,name,age) values('2334','wangwu','56');

即可插入部分,又可不按順序插入。

12、更新資料資訊

update users set name='AShun' where id='2012';

推廣: update users set name='XiaoChang',sex='Nv' where id='2012';

13、删除資料資訊

delete from users where id='2012';

推廣: delete from users //全部删除

DQL: 14、檢視資料資訊,查詢語句

select * from users;

5、幫助的使用

1、檢視幫助所能夠提供的資訊

? contents;

2、進一步檢視詳細資訊

? data types; //需是上面所列出的資訊類型

3、更進一步檢視具體資訊

? int;

? show;

? create tables; // 檢視建立表結構文法

? update;