oms 4.2.11
调用创建数据源接口报错如下:
{
"success": false,
"errorDetail": null,
"code": null,
"message": "查询数据库 mysql_test 的版本失败:Access denied for user 'myuser'@'192.168.1.100' (using password: YES)。",
"advice": null,
"requestId": "406274d4-7351-46fb-93b4-74aa65faf77f",
"pageNumber": null,
"pageSize": null,
"totalCount": null,
"cost": null,
"data": null
}
操作接口代码如下:
def createMySQLDataSource():
url = "http://192.168.1.100:8089/api/v2?Action=CreateMySqlDataSource"
payload = {
"name":"mysql_test",
"ip":"192.168.1.101",
"port":3306,
"schema":"ms",
"username":"myuser",
"password":"mypasswd",
"tryKeepHb":True,
"region":"default",
"description":"null"
}
headers = {
"Content-Type": "application/json; charset=utf-8",
"Authorization": "Basic SGVsbG8sIFdvcmxkIQo="
}
try:
response = requests.post(url, json=payload, headers=headers)
print("状态码:", response.status_code)
print("响应头 Content-Type:", response.headers.get('content-type'))
print("响应体 (JSON):")
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except requests.exceptions.RequestException as e:
print("请求发生错误:", e)
使用这个mysql的信息直接连mysql是没问题的,权限也正常,在白屏上用这个mysql信息创建数据源也是能正常创建。
# mysql -u myuser -p'mypasswd' -h 192.168.1.101 -P 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6692
Server version: 8.0.35 Source distribution
Copyright (c) 2000, 2023, 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> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for myuser@% |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO `myuser`@`%` WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>

