Home > Database > Mysql Tutorial > body text

MySQL 5.1学习笔记(1)-基本操作_MySQL

WBOY
Release: 2016-06-01 13:51:37
Original
846 people have browsed it

参考了官方文档: http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html

命令行登录数据库(mysql -uroot -p直接跟密码, 不带空格, 可以直接登录)

1 shell> mysql -ptest<br>2 shell> mysql -p test<br>3 第一个命令让mysql使用密码test,但没有指定默认数据库。第二个命令让mysql提示输入 密码并使用test作为默认数据库。
Copy after login

mysql -u root -p
输入密码

查看数据库列表
show databases

+--------------------+<br>| Database           |<br>+--------------------+<br>| information_schema |<br>| cdcol              |<br>| menagerie          |<br>| mysql              |<br>| phpmyadmin         |<br>| roadofhonda        |<br>| spring             |<br>| test               |<br>+--------------------+<br>8 rows in set (0.00 sec)
Copy after login


创建数据库
CREATE DATABASE menagerie;

切换到数据库menagerie
use menagerie

创建数据表
CREATE TABLE pet (<br>    name VARCHAR(20),<br>    owner VARCHAR(20),<br>    species VARCHAR(20),<br>    sex CHAR(1),<br>    birth DATE,<br>    death DATE<br>);
Copy after login


到mysql安装目录的data下去查看, 多了一个文件夹menagerie, 进入文件夹, 发现有这样几个文件

pet.frm 结构文件<br>pet.MYD 数据文件<br>pet.MYI 索引文件
Copy after login

查看创建表的信息
DESCRIBE pet

+---------+-------------+------+-----+---------+-------+<br>| Field   | Type        | Null | Key | Default | Extra |<br>+---------+-------------+------+-----+---------+-------+<br>| name    | varchar(20) | YES  |     | NULL    |       |<br>| owner   | varchar(20) | YES  |     | NULL    |       |<br>| species | varchar(20) | YES  |     | NULL    |       |<br>| sex     | char(1)     | YES  |     | NULL    |       |<br>| birth   | date        | YES  |     | NULL    |       |<br>| death   | date        | YES  |     | NULL    |       |<br>+---------+-------------+------+-----+---------+-------+<br>6 rows in set (0.02 sec)
Copy after login


使用文本来写pet表的数据, NULL值用/N来表示
我使用的是windows, 路径在windows下为c:/pet.txt, 但是在mysql下应该为c:/pet.txt或c://pet.txt
这个是转义字符, 想得到"/"需要输入"//"

LOAD DATA LOCAL INFILE 'c:/pet.txt' INTO TABLE pet;

pet.txt文件内容

Fluffy    Harold    cat    f    1993-02-04    /N<br>Claws    Gwen    cat    m    1994-03-17    /N<br>Buffy    Harold    dog    f    1989-05-13    /N<br>Fang    Benny    dog    m    1990-08-27    /N<br>Bowser    Diane    dog    m    1979-08-31    1995-07-29<br>Chirpy    Gwen    bird    f    1998-09-11    /N<br>Whistler    Gwen    bird    /N    1997-12-09    /N<br>Slim    Benny    snake    m    1996-04-29    /N
Copy after login


查看插入的数据
SELECT * FROM pet;

+----------+--------+---------+------+------------+------------+<br>| name     | owner  | species | sex  | birth      | death      |<br>+----------+--------+---------+------+------------+------------+<br>| Fluffy   | Harold | cat     | f    | 1993-02-04 | NULL       |<br>| Claws    | Gwen   | cat     | m    | 1994-03-17 | NULL       |<br>| Buffy    | Harold | dog     | f    | 1989-05-13 | NULL       |<br>| Fang     | Benny  | dog     | m    | 1990-08-27 | NULL       |<br>| Bowser   | Diane  | dog     | m    | 1979-08-31 | 1995-07-29 |<br>| Chirpy   | Gwen   | bird    | f    | 1998-09-11 | NULL       |<br>| Whistler | Gwen   | bird    | NULL | 1997-12-09 | NULL       |<br>| Slim     | Benny  | snake   | m    | 1996-04-29 | NULL       |<br>+----------+--------+---------+------+------------+------------+<br>8 rows in set (0.00 sec)
Copy after login

作者:icejoywoo 出处:http://www.cnblogs.com/icejoywoo/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template