一、Windows中选择一种方式安装mysql8.0
![](https://i-blog.csdnimg.cn/direct/864ec5f79411496f8d3ed6d7ef3b1e4e.png)
![](https://i-blog.csdnimg.cn/direct/e3282c74f98d4a66a2f55954d2ad4e85.png)
![](https://i-blog.csdnimg.cn/direct/56b7b28e397d406ea2ceceabfb503ec6.png)
mysql> create database mydb6_product; Query OK, 1 row affected (0.01 sec)
mysql> use mydb6_product; Database changed
列1:id,整型,主键
列2:name,字符串,最大长度50,不能为空
列3:age,整型
列4:gender,字符串,最大长度10,不能为空,默认值“unknown”
列5:salary,浮点型
mysql> create table employees(id int primary key, name varchar(50) not null, age int, gender varchar(10) not null default 'unknown', salary float);
Query OK, 0 rows affected (0.02 sec)
orders表
列1:id,整型,主键
列2:name,字符串,最大长度100,不能为空
列3:price,浮点型
列4:quantity,整型
列5:category,字符串,最大长度50
mysql> create table orders(id int primary key, name varchar(100) not null, price float, quantity int, category varchar(50));
Query OK, 0 rows affected (0.01 sec)
invoices表
列1:number,整型,主键自增长
列2:order_id,整型,外键关联到orders表的id列
列3:in date:日期型
列4:total_amount:浮点型,要求数据大于0
mysql> create table invoices(number int primary key auto_increment, order_id int, foreign key (order_id) references orders(id), in_date date, total_amount float, check(total_amount>0));
Query OK, 0 rows affected (0.05 sec)
![](https://i-blog.csdnimg.cn/direct/1b42aa1acb794eb1b795f1a63c2516f6.png)