MySQL數據庫
1.什么是數據庫? 主流數據庫都是關系型數據庫 數據庫內是有表(table)組成,表則由行和列組成。每一列稱為一個字段(或者域,field)用來定義對應列的數據類型等信息。每一行代表一條數據。 2.數據庫管理系統(tǒng)(DBMS) 管理和操縱數據庫,所有的DBMS都支持SQL結構化查詢語言。大部分的DBMS會提供圖形化管理工具。 3.數據庫管理員 4.主流的數據庫系統(tǒng) Oracle,MS SQL Server,IBM DB2,Syase PostgreSQL,MySQL,....... 5.MySQL是數據庫系統(tǒng) 開源,可免費使用 6.MySQL的基本操作 MySQL數據庫服務器的安裝 用戶的創(chuàng)建和權限管理、刪除 數據庫的創(chuàng)建和刪除 表的創(chuàng)建和刪除、修改 數據的查詢
MySQL數據庫的管理工具: MySQL官方的圖形化管理工具 第三方軟件公司開發(fā)的MySQL數據庫管理工具 MySQL自帶的命令行管理工具 phpMyAdmin:基于Web的PHP程序,專門管理MySQL數據庫服務器 MySQL的管理員是root用戶,對于應用開發(fā)來說,一般的,一個網站用一個數據庫,需要為這個網站創(chuàng)建數據庫和相應的管理員賬號。下面示例命令(用root用戶登錄后執(zhí)行): mysql> create database news; #創(chuàng)建new數據庫 mysql> grant all privileges on news.* to news@localhost identified by '123456'; #為news數據庫創(chuàng)建管理員(news用戶),并且指定密碼。 mysql> drop database news; #刪除news數據庫 使用news用戶登錄: #用news用戶連接news數據庫 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; #顯示當前數據庫中的所有表 +----------------+ | 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'); #注意括號中的值要和表的結構對應 mysql> insert into class values ('sports',2); #出錯,因為列的數據類型不匹配 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 ; #三思而后行!刪除指定表里的全部數據 mysql> delete from class where id=3; #刪除編號為3的記錄
從表中查詢數據 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等于‘army’
|