MySQL数据库
1.什么是数据库? 主流数据库都是关系型数据库 数据库内是有表(table)组成,表则由行和列组成。每一列称为一个字段(或者域,field)用来定义对应列的数据类型等信息。每一行代表一条数据。 2.数据库管理系统(DBMS) 管理和操纵数据库,所有的DBMS都支持SQL结构化查询语言。大部分的DBMS会提供图形化管理工具。 3.数据库管理员 4.主流的数据库系统 Oracle,MS SQL Server,IBM DB2,Syase PostgreSQL,MySQL,....... 5.MySQL是数据库系统 开源,可免费使用 6.MySQL的基本操作 MySQL数据库服务器的安装 用户的创建和权限管理、删除 数据库的创建和删除 表的创建和删除、修改 数据的查询
MySQL数据库的管理工具: MySQL官方的图形化管理工具 第三方软件公司开发的MySQL数据库管理工具 MySQL自带的命令行管理工具 phpMyAdmin:基于Web的PHP程序,专门管理MySQL数据库服务器 MySQL的管理员是root用户,对于应用开发来说,一般的,一个网站用一个数据库,需要为这个网站创建数据库和相应的管理员账号。下面示例命令(用root用户登录后执行): mysql> create database news; #创建new数据库 mysql> grant all privileges on news.* to news@localhost identified by '123456'; #为news数据库创建管理员(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); #上面的指令,创建了一个名称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’
|