Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4464021
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: Mysql/postgreSQL

2011-08-05 20:55:12




1.启动数据库
ywx@ywx:/opt/mysql5151$ sudo ./bin/mysqld_safe --defaults-file=./my.cnf --user=ywx &

2.连接数据库
ywx@ywx:/opt/mysql5151$ sudo ./bin/mysql --defaults-file=./my.cnf


3.查看帮助

mysql> ?


讲述如何使用数据库。只有一张表,用于存储某公司员工的基本信息,为方便描述,这里是存储员工的部分信息,包括员工号、员工姓名、员工家庭住址、员工的收入、员工的级别
   

1.创建公司数据库
mysql> create database company;

2.创建员工信息表
  1. mysql> use company;
  2. Database changed
  3. mysql> create table worker (nid int unique,name varchar(20),address varchar(200),salary float,level int);

3.插入数据
  1. mysql> insert into workervalues(100,'tom','beijing',2000.0,0);
  2. Query OK, 1 row affected (0.00 sec)

  3. mysql> insert into worker values(101,'jim','shanghai',2000.
  4. Query OK, 1 row affected (0.00 sec)

  5. mysql> insert into worker values(102,'mail','shanghai',3000.
  6. Query OK, 1 row affected (0.00 sec)

4.查询全部数据
  1. mysql> select * from worker;
  2. +------+------+----------+--------+-------+
  3. | nid | name | address | salary | level |
  4. +------+------+----------+--------+-------+
  5. | 100 | tom | beijing | 2000 | 0 |
  6. | 101 | jim | shanghai | 2000 | 1 |
  7. | 102 | mail | shanghai | 3000 | 2 |
  8. +------+------+----------+--------+-------+
  9. 3 rows in set (0.00 sec)

5.删除其中一条记录
  1. mysql> delete from worker where nid=100;
  2. Query OK, 1 row affected (0.00 sec)

  3. mysql> select * from worker; 这里已经少了 nid=100 的数据行了
  4. +------+------+----------+--------+-------+
  5. | nid | name | address | salary | level |
  6. +------+------+----------+--------+-------+
  7. | 101 | jim | shanghai | 2000 | 1 |
  8. | 102 | mail | shanghai | 3000 | 2 |
  9. +------+------+----------+--------+-------+
  10. 2 rows in set (0.00 sec)

6.更新其中一条记录
将jim的level从1级到2级,slary从2000.0更新到3000.0
  1. mysql> update worker set level=2,salary=3000.0 where nid =101;
  2. Query OK, 1 row affected (0.00 sec)
  3. Rows matched: 1 Changed: 1 Warnings: 0

  4. mysql> select * from worker; +------+------+----------+--------+-------+
  5. | nid | name | address | salary | level |
  6. +------+------+----------+--------+-------+
  7. | 101 | jim | shanghai | 3000 | 2 |
  8. | 102 | mail | shanghai | 3000 | 2 |
  9. +------+------+----------+--------+-------+
  10. 2 rows in set (0.00 sec)

7.删除数据库
   1. 删除所有的数据表,
  

  1. mysql> drop table worker;
   
   2. 删除数据库,
  1. mysql> delete database company;






阅读(5497) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~