Chinaunix首页 | 论坛 | 博客
  • 博客访问: 641982
  • 博文数量: 108
  • 博客积分: 46
  • 博客等级: 民兵
  • 技术积分: 1279
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-16 11:36
个人简介

坐井以观天

文章分类

全部博文(108)

文章存档

2014年(13)

2013年(90)

2012年(6)

分类: Mysql/postgreSQL

2013-11-24 13:53:12

原文地址:mysql创建数据库 作者:hxl

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 --
阅读(1222) | 评论(0) | 转发(0) |
0

上一篇:mysql创建存储过程

下一篇:awk 高级用法

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