Start the service:
net start mysql
Connection authentication syntax:
mysql -h localhost -p 3306 -u root -p
Close the service:
net stop mysql
Create the database:
create database 数据库名;
Create a database with library options:
create database 数据库名 charset gbk;
Select the database:
use 数据库名;
View the database creation statement:
show create database 数据库名;
Show all databases:
show databases;
Show all databases starting with my:
show databases like 'my%';
Show databases ending in bases:
show databases like '%bases';
Modify the database character set:
alter databases 数据库名 charset gbk;
Delete the database:
drop database 数据库名;
Create a table:
create table 表名(
字段名 int,
字段名 varchar(10)
);
Create a table with table options:
create table 表名(
字段名 int,
字段名 varchar(10)
)charset gbk;
Display all tables of the current library:
show tables;
View the table structure:
desc 表名;
View all tables starting with a:
show tables like 'a%';
Display table creation statement:
show create table 表名;
Copy table structure:
create table 表名2 like 表名1;
Modify the character set of the table:
alter table 表名 charset utf8;
Modify the table name:
rename table 原表名 to 新表名;
Add a new field to the table (on top):
alter table 表名 add 字段名 int[类型] first;
Add the name field to the table after the id field:
alter table 表名 add name char(10) after id;
Modify the field name, change the age field to id:
alter table 表名 change age id int;
Modify the name field type:
alter table 表名 modify name char(20);
Delete field:
alter table 表名 drop 字段名;
Delete a table:
drop table 表名;
Delete multiple tables (not allowed):
drop table 表1,表2;
Insert 1 piece of data into the table:
insert into 表名(id,name)values(1,"张三");
Insert multiple pieces of data into the table:
insert into 表名 values(1,'张三'),(2,'李四');
View all the information of the table:
select * from 表名;
Query the name and age of the student form:
select name,nl from stu;
Query the student information named Zhang San:
select * from stu where name="张三";
Delete the student information named Zhang San:
delete from stu where name="张三";
Change the id of Zhang San to 3:
update stu set id=3 where name="张三";
Set the unified character set:
set names gbk/utf8;
Increase the primary key 1:
create table 表名(
id int primary key,
name char(20)
)charset gbk;
Increase the primary key 2:
create table 表名(
id int,
name char(20),
primary key(id)
)charset gbk;
Add the primary key after the table:
alter table 表名 add primary key(字段名);
Delete the primary key:
alter table 表名 drop primary key;
Add automatic growth:
create table 表名(
id int primary key auto_increment,
name char(10) not null
)charset gbk;
Modify automatic growth:
alter table 表名 auto_increment=值;
Create a unique key:
alter table 表名add unique key(字段名);
Delete the unique key:
alter table 表名 drop index 唯一键名字;
All data in the query table:
select * from 表名;
Some fields in the query table:
select 字段列表 from 表名;
Conditional query data:
select 字段列表 * from 表名 where 字段名=值;
Delete operation:
delete from 表名 【where条件】;
Update operation:
update 表名 set 字段名=新值 【where条件】;