MySQL database basics study notes (1)

1. MySQL foundation and sql statement combat

MySQL is a relational database management system that is very popular in Internet companies.
Install with yum command under Linux

Practical operation: connect to the database 172.16.41.89
log in to mysql command:
Mysql -u root -p Enter, then enter the password
MySQL database basics study notes (1)

View databases:
Show databases;
MySQL database basics study notes (1)

Create a new database:
Create databases xiaoning defsult charset=utf8;
then show databases again to check that xiaoning has been created

MySQL database basics study notes (1)

Statement: Create table person_info (create a table named person_info)
create table person_info # Create table person_info
(
person_id smallint(5) unsigned auto_increment,#unsigned integer, primary key, auto-increment
name varchar(50) not null comment 'name ', #Non-empty, commented as name
country varchar(60) default 'China', #default is 'china'
salary decimal(10,2) default 0.00 comment 'salary', #default is 0.00, commented as salary
primary key ( person_id)#Set the person_id as the primary key
)engine=innodb default charset=utf8;#Use the InnoDB storage engine, the utf8 character set is used by default
(the above creation statement can be copied directly)
Use the client navicat, as shown below, double-click the newly created table xiaoning, and then Call up the query interface:
MySQL database basics study notes (1)
After clicking Create Query, the query edit box will appear,
copy the sql statement in the edit box, and then run

MySQL database basics study notes (1)
After the creation is successful, check the library xiaoning, and the table
MySQL database basics study notes (1)
modification table structure
statement of person_info appears: alter table person_info
There are two modification methods modify and 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 #Modify field type
Change old_col_name new_col_name column_definition#Modify field name
Practical operation:
#Use change or modify to modify the length of the country field to 50 bytes
modify statement: Alter table person_info modify country varchar(50) default 'china';
country statement : Alter table person_info change country country varchar(50) default 'china';
add field:
ADD col_name column_definition
delete field
DROP col_name

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326141180&siteId=291194637