MySql (b) introductory statement and basic operation

mysql introductory statement:
View at the library server

show databases;

Create a library (database was created after its name is not changed)

create database database name;

2.1. Look inserted library is currently located

select database();

Delete a library

drop database database name;
drop database database name IF EXISTS

database name drop database if exists;

Select the specified library

use database name;

The simplest construction of the table statement

create table msg (
Column 1 Column name Type 1,
Column 2 Column name Type 2
);

例如:create table msg(
name varchar(4),
age int
)charset utf8;

View library table

show tables; or show tables from the database name;

5.1. Interposed watch structure

desc table name;

5.2. Plug see all the data in the table

select * from 表名;

Delete table

drop table 表名;
drop talbe if exists 表名;

Change the name of the table

alter table table name rename to new table name;

View table structure

desc table name;

View the current version of the database

Method 1: Administrator Command Prompt window and have logged in to the MySQL server, enter the command: select version ();

Method 2: Sign out of the database server, the administrator at the command prompt, enter the command: mysql --version; or mysql -V;

Declaration character set

The default table built using the utf-8, but we are using in the Windows window is GBK, it is necessary to use the character set declaration.

set names gbk;

Note: If, after the current statement is wrong should denounce this statement, while continuing to fight the new statement (quit this statement: \ c)

MySQL basic operations
increased
insert into table

(Column 1, column 2, column 3)

values

; (Value column 1, column 2 value, the value of column 3)
1
2
3
. 4
. 5
. 6
. 7
of a column inserted in row

insert into msg / ** determination table ** /
(name, Age) / ** ** determine the column /
values
/ determination value ** ** /; ( 'John Doe', 18)
. 1
2
. 3
. 4
fully inserted line column (at which time all columns must be assigned, includes a primary key)

MSG INTO INSERT
values
( 'John Doe', 12);
. 1
2
. 3
inserted into a plurality of rows

MSG INTO INSERT
values
( 'Zhao six', 20),
( 'Bob', 25),
( 'red', 22);
. 1
2
. 3
. 4
. 5
puncturing
delete from table / determination table ** ** /
WHERE condition / ** certain conditions ** /
1
2
the delete from the table name (deleting the entire table)

Note: For a delete operation is to remove columns in a row of data does not exist, that is to remove the lowest per row deleted.

Change
update table / determination table ** ** /
SET = Column 1 Column 1 value / values ** ** determine the column and /
2 = value 2 columns, column
where conditions; / determination condition ** ** /
1
2
. 3
. 4
edit a piece of data to meet the conditions

MSG Update
SET Age = 89,
WHERE name = 'John Doe';
. 1
2
. 3
search
query an entire table:

select * from 表名;

Queries to meet the conditions of a column

select a column name, a column name table where 2 from the filter criteria;

Queries to meet the conditions of a row

select * from 表名 where age > 12;
--------------------- 

Guess you like

Origin www.cnblogs.com/hyhy904/p/10992428.html