- 在数据库中设计可以远程登陆的MySQL用户,并给他赋权
oj_client - 设计表结构
数据库:oj, 表:oj_questions - 开始编码
连接访问数据库
创建用户并赋权
mysql -uroot -p
进入mysql
![![[Pasted image 20250226202640.png]]](https://i-blog.csdnimg.cn/direct/c899a1a3478742df8e24f2d539c60bf1.png)
use mysql;
![![[Pasted image 20250226202738.png]]](https://i-blog.csdnimg.cn/direct/d146c5c100ed4e29bdf1ebef715764dd.png)
select User, Host from user;
![![[Pasted image 20250226202828.png]]](https://i-blog.csdnimg.cn/direct/afb9f5a4fa7d47fd889417a04640eeeb.png)
create user oj_client@'%' identified by '123456';
创建数据库oj
create database oj;
show databases;
![![[Pasted image 20250226204322.png]]](https://i-blog.csdnimg.cn/direct/c8f843c00f424bddadf340d9788c8c23.png)
show create database oj;
![![[Pasted image 20250226204402.png]]](https://i-blog.csdnimg.cn/direct/f8ec1c38ee39426b90616afdca0eb664.png)
赋权
grant all on oj.* to oj_client@'%';
测试
mysql -uoj_client -p
登录成功
![![[Pasted image 20250226204652.png]]](https://i-blog.csdnimg.cn/direct/2ffb29dc2d2749a4986e7303016749bd.png)
show databases;
![![[Pasted image 20250226204912.png]]](https://i-blog.csdnimg.cn/direct/9e4ca433504c44e5a5c8ee3748eb9149.png)
use oj;
show tables;
![![[Pasted image 20250226205022.png]]](https://i-blog.csdnimg.cn/direct/bad01b4accb3495cad83dbb62056dd9f.png)
MySQL_Workbench创建表结构
下载MySQL_Workbench
MySQL
在左边第二栏找到workbench
![![[Pasted image 20250226205926.png]]](https://i-blog.csdnimg.cn/direct/36efcc5d55bb47ea8c10ccbe3b9422ae.png)
选择链接database
![![[Pasted image 20250226210608.png]]](https://i-blog.csdnimg.cn/direct/65aef791b4704684af98c94837b5423a.png)
用oj_client链接到3306
![![[Pasted image 20250226213851.png]]](https://i-blog.csdnimg.cn/direct/08fb52c392a743ea8c064f065a298523.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]]](https://i-blog.csdnimg.cn/direct/1c041dc32ede460db7847aebb2e1ffb4.png)
点击运行
![![[Pasted image 20250226224130.png]]](https://i-blog.csdnimg.cn/direct/8325004de9744a65ad1daed3a4a9dfc1.png)
刷新
![![[Pasted image 20250226224121.png]]](https://i-blog.csdnimg.cn/direct/7911aa18822f402b9f1808a302e468d7.png)
![![[Pasted image 20250226224302.png]]](https://i-blog.csdnimg.cn/direct/1f6ef9f8bbc84d8e8fe36bde9ca66a58.png)
测试录题功能
select * from oj_questions;
选中语句,点击闪电运行
![![[Pasted image 20250226224526.png]]](https://i-blog.csdnimg.cn/direct/a1e2901186af46a48530e01f51047da2.png)
选择右边的form editor
![![[Pasted image 20250226224646.png]]](https://i-blog.csdnimg.cn/direct/79e1e77c417a4dd0abe35f29bb0550d6.png)
输入数据
![![[Pasted image 20250226225036.png]]](https://i-blog.csdnimg.cn/direct/50e8d28385fb43878c22e79ec425bde3.png)
点击apply finish
![![[Pasted image 20250226225058.png]]](https://i-blog.csdnimg.cn/direct/c4b6bc7ff5ff447b873dadb5505e3471.png)
查看到已经录入
![![[Pasted image 20250226225129.png]]](https://i-blog.csdnimg.cn/direct/94b2355dd1644dc7967572189b94b8f9.png)
select * from oj_questions;
![![[Pasted image 20250226225444.png]]](https://i-blog.csdnimg.cn/direct/8ed0d08e87244a6bbfdf5fb5015f0feb.png)


















