MySQL的安装以及库和表的使用

一 MySQLWindows版本的安装

MySQL官方网址:https://www.mysql.com/

MySQLMSI安装包地址:https://downloads.mysql.com/archives/installer/

找到第二个MSI安装包(296.1M)并下载下来,完成安装

安装过程(安装路径必须为英文):

安装依赖,若无依赖自动会安装依赖,点击下一步即可

端口,加密端口等默认即可:

认证方式:默认即可

设置root密码,密码大于八位,数字,大小写字母和特殊字符组成

安装的服务名称:默认即可,可以更改

安装路径:默认即可

点击execute检测

MySQL安装成功

注意:如果要重新安装MySQL一定要把之前下载的MySQL的文件删干净,否则第二次安装会失败

二 MySQL登录及库和表的创建

MySQL的登录:用管理员打开PowerShell

PS C:\WINDOWS\system32> mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.37 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

任务:

新建产品库mydb6_product,新建3张表如下:
employees表
列1:id,整型,主键
列2:name,字符串,最大长度50,不能为空
列3:age,整型
列4:gender,字符串,最大长度10,不能为空,默认值“unknown”
列5:salary,浮点型

orders表
列1:id,整型,主键
列2:name,字符串,最大长度100,不能为空
列3:price,浮点型
列4:quantity,整型
列5:category,字符串,最大长度50

invoices表
列1:number,整型,主键自增长
列2:order_id,整型,外键关联到orders表的id列
列3:in date:日期型
列4:total_amount:浮点型,要求数据大于0

代码实现:

# 建立mydb6_product数据库

create database mydb6_product;

#使用mydb6_product数据库

use mydb6_product;

#查看当前数据库

select database();

#建立employees表

create table (id int primary key,

name varchar(50) not null,

age int,

gender varchar(10) not null default 'unknown',

salary float);

#建立orders表

create table (id int primary key,

name varchar(100) noy null,

price float,

quantity int,

category varchar(50) );

# 建立invoices表

create table invoices(number int primary key,
order_id int ,foreign key (order_id) references orders(id),
in_date date,
total_amount float,check(total_amount>0));

#查看库中的表

show tables;

查看表中数据:

本次实验完成 ,很简单的安装以及建库建表,相信大家都掌握了,敬请期待下期!!!!

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值