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.创建员工信息表
- mysql> use company;
-
Database changed
-
mysql> create table worker (nid int unique,name varchar(20),address varchar(200),salary float,level int);
3.插入数据
- mysql> insert into workervalues(100,'tom','beijing',2000.0,0);
-
Query OK, 1 row affected (0.00 sec)
-
-
mysql> insert into worker values(101,'jim','shanghai',2000.
-
Query OK, 1 row affected (0.00 sec)
-
-
mysql> insert into worker values(102,'mail','shanghai',3000.
-
Query OK, 1 row affected (0.00 sec)
4.查询全部数据
- mysql> select * from worker;
-
+------+------+----------+--------+-------+
-
| nid | name | address | salary | level |
-
+------+------+----------+--------+-------+
-
| 100 | tom | beijing | 2000 | 0 |
-
| 101 | jim | shanghai | 2000 | 1 |
-
| 102 | mail | shanghai | 3000 | 2 |
-
+------+------+----------+--------+-------+
-
3 rows in set (0.00 sec)
5.删除其中一条记录
- mysql> delete from worker where nid=100;
-
Query OK, 1 row affected (0.00 sec)
-
-
mysql> select * from worker; 这里已经少了 nid=100 的数据行了
-
+------+------+----------+--------+-------+
-
| nid | name | address | salary | level |
-
+------+------+----------+--------+-------+
-
| 101 | jim | shanghai | 2000 | 1 |
-
| 102 | mail | shanghai | 3000 | 2 |
-
+------+------+----------+--------+-------+
-
2 rows in set (0.00 sec)
6.更新其中一条记录
将jim的level从1级到2级,slary从2000.0更新到3000.0
- mysql> update worker set level=2,salary=3000.0 where nid =101;
-
Query OK, 1 row affected (0.00 sec)
-
Rows matched: 1 Changed: 1 Warnings: 0
-
-
mysql> select * from worker; +------+------+----------+--------+-------+
-
| nid | name | address | salary | level |
-
+------+------+----------+--------+-------+
-
| 101 | jim | shanghai | 3000 | 2 |
-
| 102 | mail | shanghai | 3000 | 2 |
-
+------+------+----------+--------+-------+
-
2 rows in set (0.00 sec)
7.删除数据库
1. 删除所有的数据表,
- mysql> drop table worker;
2. 删除数据库,
- mysql> delete database company;
阅读(5504) | 评论(0) | 转发(1) |