Some simple operations for MySQL database

Source: Internet
Author: User
Tags bulk insert

After the database is started and initial security is set up, we can log in to the database.

Log in to Database

[Email protected] ~]# mysql-p

Enter Password: Enter the password for the setting

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 6

Server version:5.7.10 MySQL communityserver (GPL)

Copyright (c), Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of oraclecorporation and/or its

Affiliates. Other names trademarksof their respective

Owners.

Type ' help ', ' or ' \h ' for help. Type ' \c ' toclear the current input statement.

Mysql>

Create, delete, and view databases

Create a database

syntax:CREATE DATABASE dbname;

mysql> CREATE DATABASE Xiaowei;

Query OK, 1 row affected (0.02 sec)

Deleting a database

syntax:drop database dbname;

mysql> drop Database Xiaowei;

Query OK, 0 rows affected (0.07 sec)

View Database

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| Information_schema |

| MySQL |

| Performance_schema |

| SYS |

+--------------------+

4 rows in Set (0.05 sec)


Select the database to manipulate

mysql> use Xiaowei;

Database changed

Create a table

mysql> CREATE TABLE T1 (

ID int,

-Name varchar (20)

);

Query OK, 0 rows affected (0.04 sec)

Delete a table

mysql> drop table T1;

Query OK, 0 rows affected (0.04 sec)

View Table

Mysql> Show tables;

+-------------------+

| Tables_in_xiaowei |

+-------------------+

| T1 |

+-------------------+

1 row in Set (0.00 sec)

View the data table structure

syntax:DESC tablename;

mysql> desc T1;

+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| ID | Int (11) |     YES | |       NULL | |

| name | varchar (20) |     YES | |       NULL | |

+-------+-------------+------+-----+---------+-------+

2 rows in Set (0.08 sec)

View the data table structure in detail

syntax:show CREATE TABLE tablename;

syntax:show create TABLE t1\g; formatted output

Mysql> Show CREATE TABLE t1\g;

1. row***************************

Table:t1

Create table:create Table ' T1 ' (

' id ' int (one) DEFAULT NULL,

' Name ' varchar (DEFAULT NULL)

) Engine=innodb DEFAULT charset=latin1

1 row in Set (0.00 sec)

ERROR:

No query specified

Inserting data

Insert into T1 set

Id=1,

Name= ' Tube '

;

BULK INSERT Data

mysql> Insert into T1 values (2, ' Kevin '), (3, ' Mark ');

Query OK, 2 rows Affected (0.00 sec)

Records:2 duplicates:0 warnings:0

View data in a table

Mysql> select * from T1;

+------+-------+

| ID | name |

+------+-------+

| 1 | NULL |

| 1 | Xiaon |

| 2 | Kevin |

| 3 | Mark |

+------+-------+

4 rows in Set (0.00 sec)


This article from "Confidence snail" blog, declined reprint!

Some simple operations for MySQL database

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.