12.MySQL版题目设计|创建用户并赋权|MySQLWorkbench创建表结构|测试录题功能(mysql)

  1. 在数据库中设计可以远程登陆的MySQL用户,并给他赋权
    oj_client
  2. 设计表结构
    数据库:oj, 表:oj_questions
  3. 开始编码
    连接访问数据库

创建用户并赋权

mysql -uroot -p

进入mysql
![[Pasted image 20250226202640.png]]

use mysql;

![[Pasted image 20250226202738.png]]

select User, Host from user;

![[Pasted image 20250226202828.png]]

create user oj_client@'%' identified by '123456';

创建数据库oj

create database oj;
show databases;

![[Pasted image 20250226204322.png]]

show create database oj;

![[Pasted image 20250226204402.png]]

赋权

grant all on oj.* to oj_client@'%';
测试
mysql -uoj_client -p

登录成功
![[Pasted image 20250226204652.png]]

show databases;

![[Pasted image 20250226204912.png]]

use oj;
show tables;

![[Pasted image 20250226205022.png]]

MySQL_Workbench创建表结构

下载MySQL_Workbench
MySQL
在左边第二栏找到workbench
![[Pasted image 20250226205926.png]]

选择链接database
![[Pasted image 20250226210608.png]]

用oj_client链接到3306
![[Pasted image 20250226213851.png]]

use oj;

create table if not exists `oj_questions`(
	`number` int primary key auto_increment COMMENT '题目的编号',
    `title` varchar(128) NOT NULL comment '题目的标题',
    `star` varchar(8) NOT NULL comment '题目的难度',
    `desc` text NOT NULL comment '题目的描述',
    `header` text NOT NULL comment '对应题目预设给用户看的代码',
    `tail` text NOT NULL comment '对应题目的测试用例代码',
    `cpu_limit` int default 1 comment '对应题目的超时时间',
    `mem_limit` int default 50000 comment '对应题目的最大开辟的内存空间'
)engine=InnoDB default charset=utf8;

![[Pasted image 20250226223924.png]]

点击运行
![[Pasted image 20250226224130.png]]

刷新
![[Pasted image 20250226224121.png]]

![[Pasted image 20250226224302.png]]

测试录题功能

select * from oj_questions;

选中语句,点击闪电运行
![[Pasted image 20250226224526.png]]

选择右边的form editor
![[Pasted image 20250226224646.png]]

输入数据
![[Pasted image 20250226225036.png]]

点击apply finish
![[Pasted image 20250226225058.png]]

查看到已经录入
![[Pasted image 20250226225129.png]]

select * from oj_questions;

![[Pasted image 20250226225444.png]]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值