Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1467038
  • 博文数量: 842
  • 博客积分: 12411
  • 博客等级: 上将
  • 技术积分: 5772
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-14 14:43
文章分类

全部博文(842)

文章存档

2013年(157)

2012年(685)

分类: Mysql/postgreSQL

2012-05-23 11:24:39



OS: Red Hat Linux As 5
Mysql:5.0.22
 
1. 创建数据库
mysql> create database hxl;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hxl                |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
 
2.选择你所创建的数据库
mysql> USE hxl
Database changed
mysql> status
--------------
mysql  Ver 14.12 Distrib 5.0.22, for redhat-linux-gnu (i686) using readline 5.0
Connection id:          4
Current database:      
hxl
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.0.22
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 1 hour 25 min 32 sec
Threads: 2  Questions: 87  Slow queries: 0  Opens: 10  Flush tables: 1  Open tables: 18  Queries per second avg: 0.017
--------------
 
3.创建一个数据库表
mysql> CREATE TABLE mytable (name VARCHAR(20), *** CHAR(1),birth DATE, birthaddr VARCHAR(20));
Query OK, 0 rows affected (0.02 sec)
mysql> SHOW TABLES;
+---------------+
| Tables_in_hxl |
+---------------+
| mytable       |
+---------------+
1 row in set (0.00 sec)
 
4.显示表的结构
mysql> DESCRIBE mytable;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| name      | varchar(20) | YES  |     | NULL    |       |
| ***       | char(1)     | YES  |     | NULL    |       |
| birth     | date        | YES  |     | NULL    |       |
| birthaddr | varchar(20) | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
 
5.用文本方式将数据装入一个数据库表
vi /u01/mytest.txt输入如下内容(各字段用空格分隔)
abccs f 1977-07-07 china
mary f 1978-12-12 usa
tom m 1970-09-02 usa

mysql> LOAD DATA LOCAL INFILE "/u01/mytest.txt" INTO TABLE mytable fields terminated by ' ';
Query OK, 3 rows affected, 11 warnings (0.00 sec)
Records: 3  Deleted: 0  Skipped: 0  Warnings: 11
mysql> select * from mytable;
+-------+------+------------+-----------+
| name  | ***  | birth      | birthaddr |
+-------+------+------------+-----------+
| abccs | f    | 1977-07-07 | china     |
| mary  | f    | 1978-12-12 | usa       |
| tom   | m    | 1970-09-02 | usa       |
+-------+------+------------+-----------+
3 rows in set (0.00 sec)
-- The End --
阅读(429) | 评论(0) | 转发(0) |
0

上一篇:mysql基本知识

下一篇:sql基础

给主人留下些什么吧!~~