MySQL Learning (i)

Source: Internet
Author: User

MySQL study, this blog is about the current hot on the market of the relational database MySQL learning record.

1, about the installation of MySQL, self-Baidu.

2,sql:structure Query Language structured queries language.

SQL classification:

1,DDL (data definition Language): Define the database, the structure of the data table: Create, Drop (delete), alter (modify)

2,DML (Data Manipulation language): Mainly used to manipulate databases: Insert (insert), update (modify), delete (delete)

3,DCL (Data Customization language): Define access rights, remove access rights, security settings: Grant

4,DQL (data Query Language): Data Query Language: Select (query), from (clause), WHERE (clause)

3,dos Window Login Database

Mysql-uroot-p123 (-u followed by your database created login account,-p followed by login password. Note: Do not answer the following ";" ).

4, Database operations

Create databse database name; (note semicolon do not leak)

Create DATABASE MyDB;

To create a database specified character set

Create DATABSE database name character set character set;

Create database mydb2 character set UTF8;

Specifying proofing Rules

Create database name character Set character set collate proofing rules;

Create database mydb3 character set UTF8 collate utf8_bin;

View Database definition Statements

Show create database name;

Show CREATE Database mydb;

Modify Database

Alter DATABSE database name;

Delete a database (remember, remember)

Drop database name

Drop database mydb;

Switch database

Use database name;

Use database mydb2;

View Current Database

show databases;

5, table operation

Create a table

CREATE TABLE Table name (

field One type length constraint,

field two type length constraint,

......

);

About column-related constraints in a table

1, PRIMARY KEY constraint primary key

2, uniquely constrained unique

3, nonempty constraint NOT NULL

  

CREATE TABLE Student (

ID Int (one) primary key not NULL,

Age Int (11),

Name varchar (13)

);

View all the tables

Show tables; (View all tables under the current database)

View the creation process for a table

Show create table table name;

Show create table student;

View table Structure

DESC table name;

DESC student;

Modify Table

adding columns (ADD)

ALTER TABLE name add column name type constraint;

ALTER TABLE student add sex int not null;

Modify column (Modify)

ALTER TABLE table name modify column name type;

Alete table student Modify sex varchar (20);

Modify column name (change)

ALTER TABLE name change column list name type;

ALTER TABLE student Change sex gender int (11);

Delete Column (drop)

ALTER TABLE name drop column name;

ALTER TABLE student drop age;

Modify table (rename)

The ALTER TABLE name rename table name;

ALTER TABLE student rename S;

The above is the basic operation of the database table in MySQL, it is recommended that the novice knocks a few times have a general impression, if necessary to further study.

MySQL Learning (i)

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.