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)