http://www.runoob.com/mysql/mysql-tutorial.html
RDBMS 術(shù)語
數(shù)據(jù)庫: 數(shù)據(jù)庫是一些關(guān)聯(lián)表的集合。
數(shù)據(jù)表: 表是數(shù)據(jù)的矩陣。在一個(gè)數(shù)據(jù)庫中的表看起來像一個(gè)簡單的電子表格。
列: 一列(數(shù)據(jù)元素) 包含了相同的數(shù)據(jù), 例如郵政編碼的數(shù)據(jù)。
行:一行(=元組,或記錄)是一組相關(guān)的數(shù)據(jù),例如一條用戶訂閱的數(shù)據(jù)。
冗余:存儲(chǔ)兩倍數(shù)據(jù),冗余可以使系統(tǒng)速度更快。
主鍵:主鍵是唯一的。一個(gè)數(shù)據(jù)表中只能包含一個(gè)主鍵。你可以使用主鍵來查詢數(shù)據(jù)。
外鍵:外鍵用于關(guān)聯(lián)兩個(gè)表。
復(fù)合鍵:復(fù)合鍵(組合鍵)將多個(gè)列作為一個(gè)索引鍵,一般用于復(fù)合索引。
索引:使用索引可快速訪問數(shù)據(jù)庫表中的特定信息。索引是對(duì)數(shù)據(jù)庫表中一列或多列的值進(jìn)行排序的一種結(jié)構(gòu)。類似于書籍的目錄。
參照完整性: 參照的完整性要求關(guān)系中不允許引用不存在的實(shí)體。與實(shí)體完整性是關(guān)系模型必須滿足的完整性約束條件,目的是保證數(shù)據(jù)的一致性。
數(shù)據(jù)庫的主鍵代表了唯一標(biāo)示一條數(shù)據(jù),所以主鍵是唯一的,比如學(xué)號(hào),卡號(hào)之類的;
數(shù)據(jù)庫的外鍵是為了保證數(shù)據(jù)庫的一致性,假設(shè)表1中的一個(gè)外鍵是表2的主鍵,此時(shí)要在表2中插入一條數(shù)據(jù)時(shí)就必須查看(這條數(shù)據(jù),也就是表2的那個(gè)主鍵的信息在表1中是否存在,如果不存在則無法插入),而當(dāng)你需要在表1中刪除一條信息是,如果在表2中還存在這個(gè)數(shù)據(jù)的話也是無法直接刪除的。
MySQL安裝
http://www.cnblogs.com/endv/p/5205435.html
現(xiàn)在你可以通過以下命令來連接到Mysql服務(wù)器:
[root@host]# mysql -u root -p
Enter password:*******
Windows MySQL啟動(dòng)、關(guān)閉和密碼管理
http://blog.csdn.net/hijiankang/article/details/12044143
mysqld.exe -nt --skip-grant-tables
這個(gè)模式可以進(jìn)入無密碼登錄模式之后通過以下更新密碼
update MySQL.user set authentication_string=password('password') where user='root' ;
flush privileges;
通過以下命令安裝windows的MySQL服務(wù)
mysqld -install
之后就可以在管理員模式下使用命令來啟動(dòng)和關(guān)閉MySQL服務(wù)
net start mysql
net stop mysql
基本命令
顯示數(shù)據(jù)庫 show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
建立數(shù)據(jù)庫
create database 庫名字;
打開數(shù)據(jù)庫(進(jìn)入數(shù)據(jù)庫)
use 庫名字;
顯示數(shù)據(jù)庫中的表:
show tables;
刪除數(shù)據(jù)庫
drop database 庫名;
建立新的表
create table 表名(字段名 字段類型,...);
例如:
create table userinfo(
id int not null AUTO_INCREMENT,
name varchar(100) not null,
lasttime int ,
primary key (id)
);
這里創(chuàng)建了一個(gè)userinfo的表包含字段有id,name和lasttime,其中id為主鍵不為空,自動(dòng)增長,name不為空
顯示表的信息
SHOW COLUMNS FROM 表名;
或者
describe 表名;
插入數(shù)據(jù)
INSERT INTO table_name ( field1, field2,...fieldN )
VALUES
( value1, value2,...valueN );
例子
insert into userinfo(name,lasttime) values("reno",'20160826');
id會(huì)自動(dòng)增長不需要顯示的指定
查詢數(shù)據(jù)
select column_name,column_name FROM table_name[WHERE Clause][OFFSET M ][LIMIT N]
select * from userinfo where id=1;
更新數(shù)據(jù)
UPDATE table_name SET field1=new-value1, field2=new-value2[WHERE Clause]
update userinfo SET name="dandan" where id=2;
刪除記錄
DELETE FROM table_name [WHERE Clause]
delete from userinfo where name="dandan";
如果沒有指定 WHERE 子句,MySQL表中的所有記錄將被刪除。
你可以在 WHERE 子句中指定任何條件。