亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: php 課堂筆記4 [打印本頁]

作者: cissdy    時間: 2011-12-23 03:32
標題: php 課堂筆記4
MySQL數(shù)據(jù)庫
1.什么是數(shù)據(jù)庫?
 主流數(shù)據(jù)庫都是關(guān)系型數(shù)據(jù)庫
 數(shù)據(jù)庫內(nèi)是有表(table)組成,表則由行和列組成。每一列稱為一個字段(或者域,field)用來定義對應(yīng)列的數(shù)據(jù)類型等信息。每一行代表一條數(shù)據(jù)。
2.數(shù)據(jù)庫管理系統(tǒng)(DBMS)
 管理和操縱數(shù)據(jù)庫,所有的DBMS都支持SQL結(jié)構(gòu)化查詢語言。大部分的DBMS會提供圖形化管理工具。
3.數(shù)據(jù)庫管理員
4.主流的數(shù)據(jù)庫系統(tǒng)
 Oracle,MS SQL Server,IBM DB2,Syase
 PostgreSQL,MySQL,.......
5.MySQL是數(shù)據(jù)庫系統(tǒng)
 開源,可免費使用
6.MySQL的基本操作
 MySQL數(shù)據(jù)庫服務(wù)器的安裝
 用戶的創(chuàng)建和權(quán)限管理、刪除
 數(shù)據(jù)庫的創(chuàng)建和刪除
 表的創(chuàng)建和刪除、修改
 數(shù)據(jù)的查詢
   MySQL數(shù)據(jù)庫的管理工具:
 MySQL官方的圖形化管理工具
 第三方軟件公司開發(fā)的MySQL數(shù)據(jù)庫管理工具
 MySQL自帶的命令行管理工具
 phpMyAdmin:基于Web的PHP程序,專門管理MySQL數(shù)據(jù)庫服務(wù)器
    MySQL的管理員是root用戶,對于應(yīng)用開發(fā)來說,一般的,一個網(wǎng)站用一個數(shù)據(jù)庫,需要為這個網(wǎng)站創(chuàng)建數(shù)據(jù)庫和相應(yīng)的管理員賬號。下面示例命令(用root用戶登錄后執(zhí)行):
 mysql> create database news;     #創(chuàng)建new數(shù)據(jù)庫
 mysql> grant all privileges on news.* to news@localhost identified by '123456';  #為news數(shù)據(jù)庫創(chuàng)建管理員(news用戶),并且指定密碼。
 mysql> drop database news;       #刪除news數(shù)據(jù)庫
 使用news用戶登錄:
  #用news用戶連接news數(shù)據(jù)庫
  mysql5.5.8\bin>mysql -u news -p news
  Enter password: ******  
  mysql> create table class (id int auto_increment primary key not null,class char(20) not null);
  #上面的指令,創(chuàng)建了一個名稱class的表,含有兩個字段。
  mysql> show tables; #顯示當(dāng)前數(shù)據(jù)庫中的所有表
  +----------------+
  | Tables_in_news |
  +----------------+
  | class          |
  +----------------+
  1 row in set (0.00 sec)
mysql> describe class; #顯示class表的字段定義。
+-------+----------+------+-----+---------+----------------+
| Field | Type     | Null | Key | Default | Extra          |
+-------+----------+------+-----+---------+----------------+
| id    | int(11)  | NO   | PRI | NULL    | auto_increment |
| class | char(20) | NO   |     | NULL    |                |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> drop table class;
向表中插入記錄:
mysql> insert into class values (1,'sports'); #注意括號中的值要和表的結(jié)構(gòu)對應(yīng)
mysql> insert into class values ('sports',2); #出錯,因為列的數(shù)據(jù)類型不匹配
ERROR 1366 (HY000): Incorrect integer value: 'sports' for column 'id' at row 1
mysql> insert into class (class,id)  values ('sports',2);#正確,
mysql> insert into class(class) values('army'); #未指定id字段的值,它將自增。

從表中刪除記錄
mysql> delete from class ; #三思而后行!刪除指定表里的全部數(shù)據(jù)
mysql> delete from class where id=3; #刪除編號為3的記錄


從表中查詢數(shù)據(jù)
mysql> select * from class  ; #顯示表中全部記錄的全部字段
mysql> select * from class where id = 10; #顯示id為10的記錄
mysql> select * from class where id < 10; #顯示id小于10的記錄
mysql> select * from class where id between 5 and 10;#顯示id號為5~10之間的所有記錄
mysql> select * from class where id < 10 and class='army';#顯示id<10并且class等于‘a(chǎn)rmy’


 





歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2