• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

MySQL入门学习(六)

发布: 2007-7-02 11:08 | 作者: admin | 来源: | 查看: 8次 | 进入软件测试论坛讨论

领测软件测试网 MySQL入门学习(六)
--修改和备份、批处理

  有时我们要对数据库表和数据库进行修改和删除,可以用如下方法实现:

1、增加一列:
如在前面例子中的mytable表中增加一列表示是否单身single:
mysql> alter table mytable add column single char(1);

2、修改记录
将abccs的single记录修改为“y”:
mysql> update mytable set single=@#y@# where name=@#abccs@#;

现在来看看发生了什么:
mysql> select * from mytable;
+----------+------+------------+-----------+--------+
| name   | sex | birth   | birthaddr | single |
+----------+------+------------+-----------+--------+
| abccs  |f   | 1977-07-07 | china   | y   |
| mary   |f   | 1978-12-12 | usa    | NULL  |
| tom   |m   | 1970-09-02 | usa    | NULL  |
+----------+------+------------+-----------+--------+

3、增加记录
  前面已经讲过如何增加一条记录,为便于查看,重复与此:
mysql> insert into mytable
  -> values (@#abc@#,@#f@#,@#1966-08-17@#,@#china@#,@#n@#);
Query OK, 1 row affected (0.05 sec)
查看一下:
mysql> select * from mytable;
+----------+------+------------+-----------+--------+
| name   | sex | birth   | birthaddr | single |
+----------+------+------------+-----------+--------+
| abccs  |f   | 1977-07-07 | china   | y   |
| mary   |f   | 1978-12-12 | usa    | NULL  |
| tom   |m   | 1970-09-02 | usa    | NULL  |
| abc   |f   | 1966-08-17 | china   | n   |
+----------+------+------------+-----------+--------+


3、删除记录
用如下命令删除表中的一条记录:
mysql> delete from mytable where name=@#abc@#;
DELETE从表中删除满足由where给出的条件的一条记录。

再显示一下结果:
mysql> select * from mytable;
+----------+------+------------+-----------+--------+
| name   | sex | birth   | birthaddr | single |
+----------+------+------------+-----------+--------+
| abccs  |f   | 1977-07-07 | china   | y   |
| mary   |f   | 1978-12-12 | usa    | NULL  |
| tom   |m   | 1970-09-02 | usa    | NULL  |
+----------+------+------------+-----------+--------+

4、删除表:
mysql> drop table ****(表1的名字),***表2的名字;
可以删除一个或多个表,小心使用。

5、数据库的删除:
mysql> drop database 数据库名;
小心使用。

6、数据库的备份:
退回到DOS:
mysql> quit
d:mysqlbin
使用如下命令对数据库abccs进行备份:
mysqldump --opt abccs>abccs.dbb
abccs.dbb就是你的数据库abccs的备份文件。

7、用批处理方式使用MySQL:

首先建立一个批处理文件mytest.sql,内容如下:
use abccs;
select * from mytable;
select name,sex from mytable where name=@#abccs@#;

在DOS下运行如下命令:
d:mysqlbin mysql < mytest.sql
在屏幕上会显示执行结果。

如果想看结果,而输出结果很多,则可以用这样的命令:
mysql < mytest.sql | more

我们还可以将结果输出到一个文件中:
mysql < mytest.sql > mytest.out

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网