数据库基本操作
连接数据库:
mysql -u root -p (输入密码);
创建数据库:
create database test;
如果系统没有 test 的数据库,则创建一个使用utf8mb4字符集的 test 数据库,如果有则
不创建
create database if not exists test character set utf8mb4;
使用数据库:
use test;
删除数据库:
drop database if exists test;
数据库基本类型
1—bit ----------------------Boolean
1—tinyint ------------------Byte
2—smallint ----------------Short
4—int ------------------------Integer
8—bigint --------------------Long
4—float (M,D)----------------------Float单精度(M是长度,D是小数位数)
8—double (M,D)-------------------Double
MD最大值+2—decimal (M,D)------------------BigDecimal双精度
numeric(M,D) -------------------BigDecimal
varchar ------------------String(可变长度字符串)
text ----------------------String(长文本数据)
8—detatime ---------------java,util.Date//java.sql.Timestamp不会进行时区转换
4—timestamp -----------------java,util.Date//java.sql.Timestamp会进行时区转换
表的操作
查看表结构:
desc test;
创建表
create table test(
id int,
name varchar(20),
age int
);
删除表
drop table test;
test已经存在drop table if exists test;