MySQL Database-----Basic command operations

Source: Internet
Author: User
Tags mysql version mysql login

Small series has been wanting to know, how to build a database, here to share some of the preparatory work before this, first of all the small part is the first to understand the database (MySQL), the following is a small part of the understanding:

First, MySQL common commands
1. mysql Login and logout
Login:mysql[-h host/IP]-u user name-P ENTER
Enter Password: specific password

eg


exit:exit

eg


other launches:quit \q
2. mysql Common commands
Select Now (); View current time


Select Curdate (); View current date


Select Curtime (); View time


Select version (); MySQL version


Select User (); View users

Ii. data tables and data types

A SQL statement can be divided into 3 categories:
DDL (Data definition languages) statements: A data definition language that defines different data segments, number
database objects such as libraries, tables, columns, indexes, and so on. The commonly used statement keywords include create, drop, alter and so on.
DML (Data manipulation Languages) statement: Data manipulation statements for adding, deleting, updating, and querying numbers
and check data integrity, commonly used statement keywords include insert, delete, udpate and select and so on.
DCL (Data Control Languages) statement: Data control statements for controlling the direct license and interview of different data segments.
the level of the query. This statement defines the database, table, field, user's access rights, and security level. Key statement Keywords
includes Grant, REVOKE, and so on.
1. Use the command:
"1, show databases; View the currently owned system libraries


Information schema log information, not necessarily in other versions (reason: different version information)
Mysql:mysql System Library
Test: Testing Library
2. Create the database
create database name;
Eg:create database demo;


3. Delete the database
Drop database demo;


4. Using the database
Use database name;




create table datasheet name
(
Column definition:

column name type [default]

.....
index definition;
);


2. View the properties of a table
DESC tablename; This command can be visually viewed in the form of a two-dimensional table, the content is not detailed
OR
Show CREATE TABLE tablename \g; This command can not only implement the above content properties, but also see the table's
Engine (storage engines) and CharSet (character set).
The meaning of the "\g" option is that records can be arranged vertically by field, making it easier to display records with longer content.


3. Delete the table
DROP table TableName;


4, modify the table
For tables that have already been built, especially those that already have data, if you make some changes to the data structure, you can use the following
Common statements:
A, modify the type of table:
ALTER TABLE tablename Modify[column] column_definition [First | after_name];


B. Add table field:
ALTER TABLE tablename Add[column] column_definition [Firat | after_name];


C. Delete table fields:
ALTER TABLE tablename Drop[column] COLUMN;


D, rename the field:
ALTER TABLE tablename Change[column] old-col-name column_definition [First |
After_ Col_name];


E. Modify the order of the fields:
In the previous field increment and modify Syntax (add/change/modify), there is an optional (first | After--name), this option can be used to modify the position of the field in the table where the default Add new field is added to the last position of the table, and change/modify does not change the position of the field by default.
For example:
@1, add new field Ewangxiao after ename
ALTER TABLE Zhangxiao add Ewangxiao varchar (a) after ename;


@2, modify the field Ezhangxiaoxia, and put it in the front
ALTER TABLE Zhangxiao Modify Ezhangxiaoxia varchar (+) first;

The above command is a command of the DDL statement and will continue to describe the remaining DML statements with the DCL Statement!!!

MySQL Database-----Basic command operations

Related Article

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.