| 
      
        | MySQL入门指南,希望对大家用处!!  |  
        | 
          
            |  |  
            | 来源:互联网  作者:未知  发布时间:2007-12-08 |  
            |  |  |  
        
          | 
 mysql>use database01
 database changed.
 
 4.创建表
 mysql>create table table01 (field01 integer, field02 char(10));
 Query OK, 0 rows affected (0.00 sec)
 
 5.列出表清单
 mysql>show tables;
 Tables in database01
 Table01
 table02
 
 6.列出表中的字段清单
 mysql>show columns from table01;
 Field Type Null Key Default Extra
 field01 int(11) YES
 field02 char(10) YES
 
 7.表的数据填写
 插入数据
 mysql>insert into table01 (field01, field02) values (1, 'first');
 Query OK, 1 row affected (0.00 sec)
 
 8.字段的增加
 ...一次一个字段
 mysql>alter table table01 add column field03 char(20);
 Query OK, l row affected (0.04 sec)
 Records: 1 Duplicates: 0 Warnings: 0
 ...一次多个字段
 mysql>alter table table01 add column field04 date, add column field05 time;
 Query OK, l row affected (0.04 sec)
 Records: 1 Duplicates: 0 Warnings: 0
 注意:每一列都必须以"add column"重新开始。  php程序员站
 它运行了吗?让我们看看。
 mysql>select * from table01;
 field01 field02 field03 field04 field05
 1 first NULL NULL NULL
 
 9.多行命令输入
 MySQL命令行界面允许把陈述作为一行输入,也可以把它展开为多行输入。这两者之间并没有语法上的区别。使用多行输入,你可以将SQL陈述一步步分解,从而使你更容易理解。
 在多行方式下,注释器把每一行都添加到前面的行后,直到你用分号";"来结束这个SQL陈述。一旦键入分号并按回车键,这个陈述即被执行。
 下面的例子是同一个严格的SQL陈述的两种输入方法:
 单行输入
 Mysql>create table table33 (field01 integer, field02 char(30));
 多行输入
 Mysql>create table table33
 ->(field01
 ->integer,
 ->field02
 ->char(30));
 注意不能将单词断开,如:
 正确
 mysql>create table table33
 ->( field01
 ->integer,
 ->field02
 ->char(30));
 错误
 mysql>create table table33
 ->( field01 inte
 ->ger,
 ->field02
 ->char(30));
 www.phperz.com 当插入或更改数据时,不能将字段的字符串展开到多行里,否则硬回车将被储存到数据中:
 标准操作
 mysql>insert into table33 (field02)
 ->values
 ->('who thought of foo?');
 硬回车储存到数据中
 mysql>insert into table33 (field02)
 ->values
 ->('who thought
 ->of foo?');
 结果如下:
 mysql>select * from table33;
 field01 field02
 NULL who thought of foo?
 NULL who thought
 Of foo?
 
 10.表的数据嵌入
 mysql>insert into table01 (field01, field02, field03, field04, field05) values
 ->(2, 'second', 'another', '1999-10-23', '10:30:00');
 Query OK, 1 row affected (0.00 sec)
 标准日期格式是"yyyy-mm-dd"。
 标准时间格式是"hh:mm:ss"。
 引号内要求所给的是上述的标准日期和时间格式。
 日期也可以"yyyymmdd"形式,时间也可以"hhmmss"形式输入,但其值不需要再加引号。
 数字值不需要加引号。这种保存与数据类型无关,这些数据类型都有格式化的专栏来包含(例如:文本,日期,时间,整数等)。  www.phperz.com
 MySQL有一个很有用的命令缓冲区。它保存着你目前已经键入的SQL语句利用它,对于相同的命令,你就不必一遍又一遍地重复输入。下一步我们就来看这样的一个例子。
 利用命令缓冲区(及任意的日期和时间格式)增加另一个数据
 按两次键盘上的向上箭头键。
 回车。
 在圆括号内输入新的值,并以分号结尾。
 (3, 'a third', 'more', 19991024, 103004);
 回车。
 新值存在里面了吗?
 mysql>select * from table01;
 field01 field02 field03 field04 field05
 1 first NULL NULL NULL
 2 second another 1999-10-23 10:30:00
 3 a third more 1999-10-24 10:30:04
 
 11.表的数据更新
 一次修改一个字段
 再次注意语法。文本需要加引号但数字不要。
 mysql>update table01 set field03='new info' where field01=1;
 Query OK, 1 row affected (0.00 sec)
 一次改变多个字段
 记住在每一个更新的字段间用逗号隔开。
 mysql>update table01 set field04=19991022, field05=062218 where field01=1;
 Query OK, 1 row affected (0.00 sec)
 一次更新多个数据
 mysql>update table01 set field05=152901 where field04>19990101;  php程序员站
 Query OK, 3 rows affected (0.00 sec)
 
 12.删除数据
 mysql>delete from table01 where field01=3;
 Query OK, 1 row affected (0.00 sec)
 
 13.退出
 mysql>quit
 Bye
 现在你已经了解了一些运行MySQL中的数据库的根本命令。由于MySQL是通过执行SQL调用来操作的,在你的处理过程中需要一个强有力工具的充足的数组。例如,通过联接相关的字段,你可以同时显示几个表中的数据。同样,SQL允许综合显示、更新或者删除多个符合具体标准的数据。如果你还想精通掌握它,下一步就要学习所有SQL的知识。
 另外说明一下,MySQL提供了很好的网络操作安全特性。要想了解MySQL的安全及其它特性的详情,请查询MySQL网站:http://www.mysql.com
 为了方便大家查询使用MySQL手册, 我们将官方手册(Manaul)做在光盘的/docs/manaul/mysql目录下.大家可以用浏览器浏览查询.
 
   phperz~com  
 |  
          | 上一页 1 2下一页 |  
          | [收藏此页] [打印本页] [返回顶部] |  |