MySQL学习
一.MySQL库的基本操作
1.创建数据库
格式:
create database 数据库名;
create database 数据库名 character set 编码;
create database 数据库名 charset 编码;
create database hcq_db;
2.查询数据库
格式:
show create database 数据库名;
show create database hcq_db;
3.修改数据库编码
格式:
alter database 数据库名 character set 编码;
alter database 数据库名 charset 编码;
alter database hcq_db character set gbk;
4.删除数据库
格式:
drop database 数据库名;
drop database hcq_db;
切换到某数据库:
格式:
use 数据库名;
use hcq_db;
二.创建表
格式:
create table 表名(
列名1 数据类型 [一些约束信息],
列名2 数据类型 [一些约束信息],
列名2 数据类型
)[engine=innoDB character set 编码];
先创建好数据库并切换到该数据库
create table student(
sid int,
sname varchar(20),
age int );
1.查询创建表
格式:
show create table 表名;
show create table student;
2.修改表信息
2.1.修改表名称
格式:
alter table 旧表名 rename as 新表名;
alter table student rename as tb_hcq;
展示所有表:
show tables;
3.修改表引擎和编码
格式:
alter table 表名 engine=引擎名 character set 编码;
alter table 表名 engine=引擎名 charset 编码;
alter table 表名 engine=引擎名;
alter table 表名 charset 编码;
mysql> alter table tb_hcq engine= myisam charset gbk;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0