MySQL5.1 study notes (1)-basic operations _ MySQL

Source: Internet
Author: User
MySQL5.1 study notes (1)-basic operations refer to the official documentation: http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html

Log on to the database through the command line (mysql-uroot-p directly follows the password without spaces. you can log on directly)

1 shell> mysql-ptest
2 shell> mysql-p test
3. the First Command allows mysql to use the password test, but the default database is not specified. The second command prompts mysql to enter the password and use test as the default database.

Mysql-u root-p
Enter password

View database list
Show databases

+--------------------+
| Database |
+--------------------+
| information_schema |
| cdcol |
| menagerie |
| mysql |
| phpmyadmin |
| roadofhonda |
| spring |
| test |
+--------------------+
8 rows in set (0.00 sec)


Create a database
Create database menagerie;

Switch to the database menagerie
Use menagerie

Create a data table
CREATE TABLE pet (
name VARCHAR(20),
owner VARCHAR(20),
species VARCHAR(20),
sex CHAR(1),
birth DATE,
death DATE
);


Go to the data directory of the mysql installation directory and check the menagerie folder. enter the folder and find several files.

Pet. frm structure file
Pet. MYD data file
Pet. MYI index file

View the information of the created table
DESCRIBE pet

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


Use text to write data in the pet table. The NULL value is expressed by/N.
In windows, the path is c:/pet.txt, but in mysql, it should be c:/pet.txt or c: // pet.txt.
This is an escape character. to get "/", enter "//"

Load data local infile 'C:/pet.txt 'into table pet;

Pet.txt file content

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


View inserted data
SELECT * FROM pet;

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

Author: icejoywoo Source: http://www.cnblogs.com/icejoywoo/ this article copyright belong to the author and blog Park a total, welcome to reprint, but without the author's consent must retain this paragraph of the statement, and in the article page clearly given the original connection, otherwise, you are entitled to pursue legal liability.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.