postman也可以连接mysql

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

目录

1、安装

2、启动服务

3、执行sql语句

 

1、安装

想要postman连接mysql,需要安装xmysql,启动该服务,然后才可以调用。

预置条件:完成nodejs和npm的安装

安装时要注意版本的匹配问题,用法和注意事项可查看https://github.com/o1lab/xmysql#xmysql--one-command-to-generate-rest-apis-for-any-mysql-database

 

postman连接mysql执行操作 随笔 第1张

postman连接mysql执行操作 随笔 第2张

安装xmsql:

 npm install -g xmysql

postman连接mysql执行操作 随笔 第3张

 

2、启动服务

启动xmysql:

xmysql的相关启动参数,可以通过xmysql -h查看

postman连接mysql执行操作 随笔 第4张

xmysql -h host_name -u user_name -p user_password -d database_name -o port

备注:-h,-u,-p,-o:要连接的数据库的信息, -r,-n想要启动xmysql服务机器的信息

postman连接mysql执行操作 随笔 第5张

 

3、执行sql语句

启动xmysql后,即可通过http://localhost:3000/api/ 访问 xmysql 自动生成的 Rest API,详细的使用方法可通过https://github.com/o1lab/xmysql查看

备注:localhost是mysql服务要启动的机器的ip,3000是xmysql服务默认端口,可在启动时通过-r修改

case1:查询某表数据,get请求:http://localhost:3000/api/table_name:

postman连接mysql执行操作 随笔 第6张

case2:按某种条件查询,get请求:http://localhost:3000/api/table_name?_where=(username,eq,root)

postman连接mysql执行操作 随笔 第7张

case3:查询几行:get请求:http://localhost:3000/api/table_name?_fields=username,password,特殊的,分页_p=x&_size=x   

postman连接mysql执行操作 随笔 第8张

case4:插入数据,post请求:http://localhost:3000/api/table_name:

postman连接mysql执行操作 随笔 第9张

 

case5:新用patch、删除用delete

postman连接mysql执行操作 随笔 第10张

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄