MySQL Database Basics Learning Notes (i)

Source: Internet
Author: User

1, MySQL Foundation and SQL statement Combat

MySQL is a relational database management system, which is very popular in internet companies.
Install with the Yum command under Linux

Real: Connect database 172.16.41.89
Log in to MySQL command:
Mysql-u root-p Return, then enter the password

To view the database:
Show databases;

New database:
Create databases xiaoning Defsult Charset=utf8;
Then show databases again, Xiaoning has been created

Statement: CREATE TABLE Persion_info (creates a table named Persion_info)
Create tables Person_info # Person_info
(
person_id smallint (5) unsigned auto_increment, #无符号整型, primary key, auto grow
Name varchar () NOT NULL comment ' name ', #非空, comment as name
Country varchar default ' China ', #默认为 ' China '
Salary decimal (10,2) default 0.00 comment ' wages ', #默认为0.00, note as Payroll
Primary Key (person_id) #设置persion_id为主键
) engine=innodb default Charset=utf8; #使用InnoDB存储引擎, using the UTF8 character set
(the above creation statement can be copied directly)
Use the client navicat, for example, double-click the newly created table xiaoning, and then bring up the query interface:

Click Create Query, the query edit box appears,
in the edit box to copy the SQL statement, and then run


After a successful creation, view the library xiaoning, the table that appears Person_info

Modify Table Structure
Statement: ALTER TABLE Person_info
There are two ways to modify modify, change
Description: Col_name column Name
column_definition field type
Old_col_name Original Column Name
New_col_name New Column Name
Statement format:
Modify col_name column_definition# modifying field types
Change Old_col_name new_col_name column_definition# Modify field name
Real:
#使用change或者modify两种方法修改country字段长度为50字节
Modify statement: Alter table person_info Modify country varchar () default ' China ';
Country statement: Alter table person_info Change country country varchar (.) Default ' China ';
Add Field:
ADD col_name column_definition
Delete a field
DROP col_name

MySQL Database Basics Learning Notes (i)

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.