MySQL Router Restful API (中文)
MySQL 路由器允许应用程序对后端 MySQL InnoDB Cluster 的 MySQL 服务器进行透明路由访问。
从 MySQL 8.0.17 版本起,Restful API(Http 访问)功能已经被添加到 MySQL Router。
本文旨在提供使用 Router Restful API 的教程。在MySQL 8.0.29 版本上测试过。
设置和假设
1. MySQL InnoDB Cluster 8.0.29 - 集群名称为“mycluster”
2. 安装 MySQL Shell 8.0.29 和使用 Linux 操作系统
3. Restful API 用户:'myapiuser'
路由器配置
Bootstrap 是创建路由器配置设置的过程。
例如
$> mysqlrouter --bootstrap admin:adminPassword@node1:node1Port --directory /tmp/myrouter --account routerfriend --account-create always
创建出来的 /tmp/myrouter 目录有配置、密钥和脚本。
默认在 mysqlrouter.conf 设置定义里,启用 8443 的Http Port 为 API 端口。
---
[http_server]
port=8443
ssl=1
ssl_cert=/tmp/myrouter/data/router-cert.pem
ssl_key=/tmp/myrouter/data/router-key.pem
[http_auth_realm:default_auth_realm]
backend=default_auth_backend
method=basic
name=default_realm
[rest_router]
require_realm=default_auth_realm
[rest_api]
[http_auth_backend:default_auth_backend]
backend=metadata_cache
[rest_routing]
require_realm=default_auth_realm
[rest_metadata_cache]
require_realm=default_auth_realm
---
路由器帐户设置
身份验证在 mysqlrouter.conf 下配置为 'backend=metadata_cache'
[http_auth_backend:default_auth_backend]
backend=metadata_cache
Restful api 用户表 mysql_innodb_cluster_metadata.v2_router_rest_accounts 定义Restful API 的用户。
以下步骤提供有关用户创建的详细信息
1. 使用具有用户创建权限的 root 或管理员登录 MySQL 服务器节点(主节点),并创建用户帐户(例如:myapiuser) - 这是一个虚拟帐户,将在第 3 步中删除。
mysql> CREATE USER myapiuser IDENTIFIED BY 'myapiuser';
2. 创建用户帐户条目 - 密码是来自 mysql.user 的authentication_string。以下SQL是在路由rest用户表account“v2_router_rest_accounts”创建用户名='myapiuser'。可以根据您的设置进行更改。
mysql> INSERT INTO mysql_innodb_cluster_metadata.v2_router_rest_accounts
( cluster_id, user, authentication_method, authentication_string, description, privileges, attributes)
SELECT cluster_id, user, 'modular_crypt_format', authentication_string, 'api user', null, null
FROM mysql_innodb_cluster_metadata.clusters, mysql.user
WHERE user='myapiuser' and cluster_name = 'mycluster'
3. 用户“myapiuser”可以被删除。
mysql> DROP USER myapiuser;
通过浏览器访问Restful API(以Chrome浏览器为例)
Restful API http 端口打开为 8443。可以通过 URL 访问 swagger.json:
https://<MySQL Router IP>:8443/api/20190715/swagger.json
api/20190715/ - 它是 API 基本路径。
它还显示可以通过 API 基本路径访问的“路径”列表。
要访问详细信息,需要用户/密码才能访问。
例如,检查路由器状态 - https://Router IP:8443/api/20190715/router/status
输入之前在路由器帐户设置中创建的用户/密码可以访问状态,如下所示:
可以尝试其他 Restful API paths、metadata/connection/routes 等等 详细信息。
参考:
https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-rest-api-setup.html
https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-innodb-cluster.html
https://dev.mysql.com/doc/relnotes/mysql-router/en/news-8-0-17.html
https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-deploying-bootstrapping.html
相关文章
- MySQL管理工具安装说明[通俗易懂]
- 乱码解决MySQL中文乱码问题(mysql中文)
- MySQL主从同步: 监控维护的利器(mysql主从同步监控)
- 解析MySQL实例解析:简单易懂的指导(mysql实例案例)
- MySQL中实现多对多查询的技巧(mysql多对多查询语句)
- MySQL连接错误:无法连接服务器(无法连接mysql服务器)
- 类型MySQL中的日期列类型:特性及用法(mysql日期列)
- MySQL:处理中文字符串的技巧(mysql中文字符串)
- 优化MySQL联合查询的秘诀(mysql联合查询优化)
- 数据MySQL中插入中文数据的操作方法(mysql中插入中文)
- 快速掌握JS操作MySQL数据库技巧(js操作mysql数据库)
- MySQL解决中文乱码的方法(mysql保存中文乱码)
- 深入理解MySQL的进程管理(mysql进程)
- MySQL表同步之跨库之路(mysql表同步不同库)
- 支持MySQL字符集:如何实现中文支持(mysql字符集中文)
- Mysql中实现两数相除的方法简介(mysql中两个数相除)
- 25字中文标题MySQL表中不允许重复数据的处理方法(mysql中不能重复)
- C语言玩转MySQL构建你的代码块(c 使用mysql代码块)
- MySQL数据表ID重置方法简介(mysql中id清零开始)
- 使用C语言定义MySQL参数介绍及实战(c mysql参数定义)
- 深入了解MySQL空间管理是必须的(mysql一般要空)
- 将MySQL下载到C盘的详细步骤(mysql下载到了c盘)
- MySQL下载中文破解,简单快捷轻松掌握(mysql下载中文破解)
- MySQL中文输入无效无法粘贴中文(mysql 不能粘贴中文)
- 使用MySQL时需要注意不支持中文输入(mysql 不能使用中文)
- 解决方案MySQL数据库无法接受中文字符的问题(mysql不接受中文)