Getting started with MySQL-quick reference (2) _ MySQL

Source: Internet
Author: User
Tags type null
MySQL Getting Started Guide-quick reference (2) II. MySQL User Guide

1. use MySQL to create a new database

Run in shell:

$> Mysqladmin create database01

Database "database01" created.

2. start MySQL

Run in shell:

$> Mysql

Welcome to the MySQL monitor. Commands end with; or g.

Your MySQL connection id is 22 to server version: 3.21. 29a-gamma-debug

Type 'HELP' for help.

3. change the database

Mysql> use database01

Database changed.

4. create a table

Mysql> create table table01 (field01 integer, field02 char (10 ));

Query OK, 0 rows affected (0.00 sec)

5. list tables

Mysql> show tables;

Tables in database01

Table01

Table02

6. list fields in the table

Mysql> show columns from table01;

Field Type Null Key Default Extra

Field01 int (11) YES

Field02 char (10) YES

7. enter data in the table

Insert data

Mysql> insert into table01 (field01, field02) values (1, 'first ');

Query OK, 1 row affected (0.00 sec)

8. add fields

... One field at a time

Mysql> alter table table01 add column field03 char (20 );

Query OK, l row affected (0.04 sec)

Records: 1 Duplicates: 0 Warnings: 0

... Multiple fields at a time

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

Note: Each column must start again with "add column.

Is it running? Let's take a look.

Mysql> select * from table01;

Field01 field02 field03 field04 field05
1 first NULL

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.