📄 mysql入门学习(六).htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0057)http://eps.www85.cn4e.com/java/article/devshow.asp?id=146 -->
<HTML><HEAD><title>csdn_MySQL入门学习(六)</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE type=text/css>TD {
FONT-FAMILY: "Verdana", "Arial", "宋体"; FONT-SIZE: 9pt
}
A {
COLOR: #660000; TEXT-DECORATION: underline
}
A:hover {
COLOR: #660000; TEXT-DECORATION: none
}
.line {
LINE-HEIGHT: 14pt
}
</STYLE>
<META content="MSHTML 5.00.2920.0" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff text=#000000>
<table><tbody>
<TR>
<TD height=21>
<DIV align=center><B><FONT size=3>MySQL入门学习(六) <BR><FONT
size=2>
</FONT></FONT></FONT>
<HR align=center color=#cccccc noShade SIZE=1>
</DIV></TD></TR>
<TR>
<TD class=line><FONT
color=#333300>MySQL入门学习(六) <BR>--修改和备份、批处理 <BR><BR> 有时我们要对数据库表和数据库进行修改和删除,可以用如下方法实现: <BR><BR>1、增加一列: <BR>如在前面例子中的mytable表中增加一列表示是否单身single: <BR>mysql> alter table mytable add column single char(1); <BR><BR>2、修改记录 <BR>将abccs的single记录修改为“y”: <BR>mysql> update mytable set single='y' where name='abccs'; <BR><BR>现在来看看发生了什么: <BR>mysql> select * from mytable; <BR>+----------+------+------------+-----------+--------+ <BR>| name | sex | birth | birthaddr | single | <BR>+----------+------+------------+-----------+--------+ <BR>| abccs |f | 1977-07-07 | china | y | <BR>| mary |f | 1978-12-12 | usa | NULL | <BR>| tom |m | 1970-09-02 | usa | NULL | <BR>+----------+------+------------+-----------+--------+ <BR><BR>3、增加记录 <BR> 前面已经讲过如何增加一条记录,为便于查看,重复与此: <BR>mysql> insert into mytable <BR> -> values ('abc','f','1966-08-17','china','n'); <BR>Query OK, 1 row affected (0.05 sec) <BR>查看一下: <BR>mysql> select * from mytable; <BR>+----------+------+------------+-----------+--------+ <BR>| name | sex | birth | birthaddr | single | <BR>+----------+------+------------+-----------+--------+ <BR>| abccs |f | 1977-07-07 | china | y | <BR>| mary |f | 1978-12-12 | usa | NULL | <BR>| tom |m | 1970-09-02 | usa | NULL | <BR>| abc |f | 1966-08-17 | china | n | <BR>+----------+------+------------+-----------+--------+ <BR><BR><BR>3、删除记录 <BR>用如下命令删除表中的一条记录: <BR>mysql> delete from mytable where name='abc'; <BR>DELETE从表中删除满足由where给出的条件的一条记录。 <BR><BR>再显示一下结果: <BR>mysql> select * from mytable; <BR>+----------+------+------------+-----------+--------+ <BR>| name | sex | birth | birthaddr | single | <BR>+----------+------+------------+-----------+--------+ <BR>| abccs |f | 1977-07-07 | china | y | <BR>| mary |f | 1978-12-12 | usa | NULL | <BR>| tom |m | 1970-09-02 | usa | NULL | <BR>+----------+------+------------+-----------+--------+ <BR><BR>4、删除表: <BR>mysql> drop table ****(表1的名字),***表2的名字; <BR>可以删除一个或多个表,小心使用。 <BR><BR>5、数据库的删除: <BR>mysql> drop database 数据库名; <BR>小心使用。 <BR><BR>6、数据库的备份: <BR>退回到DOS: <BR>mysql> quit <BR>d:mysqlbin <BR>使用如下命令对数据库abccs进行备份: <BR>mysqldump --opt abccs>abccs.dbb <BR>abccs.dbb就是你的数据库abccs的备份文件。 <BR><BR>7、用批处理方式使用MySQL: <BR><BR>首先建立一个批处理文件mytest.sql,内容如下: <BR>use abccs; <BR>select * from mytable; <BR>select name,sex from mytable where name='abccs'; <BR><BR>在DOS下运行如下命令: <BR>d:mysqlbin mysql < mytest.sql <BR>在屏幕上会显示执行结果。 <BR><BR>如果想看结果,而输出结果很多,则可以用这样的命令: <BR>mysql < mytest.sql | more <BR><BR>我们还可以将结果输出到一个文件中: <BR>mysql < mytest.sql > mytest.out <BR></FONT></TD></TR>
<TR>
<TD height=5>
<HR align=center color=#cccccc noShade SIZE=1>
</TD></TR></TBODY></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -