【问题标题】:Connect python code to PCF MYSQL service instance将 python 代码连接到 PCF MYSQL 服务实例
【发布时间】:2020-11-14 00:56:35
【问题描述】:

是否可以将我的 python 代码连接到 PCF 中的 mysql 服务实例? 如果是,如何在下面的代码中填充连接详细信息?有什么建议。 我想在本地机器上运行 python 代码。

代码:

import mysql.connector
from mysql.connector import Error

try:
     connection = mysql.connector.connect(host='XXXXXXX',
                                          database='XXXXXXXXX',
                                          user='XXXXX',
                                          password='XXXXXXXXX')

    
    mySql_Create_Table_Query = """CREATE TABLE example( 
                             Id int(11) NOT NULL,
                             Name varchar(250) NOT NULL) """

    cursor = connection.cursor()
    result = cursor.execute(mySql_Create_Table_Query)
    print("btp Table created successfully ")

except mysql.connector.Error as error:
    print("Failed to create table in MySQL: {}".format(error))
finally:
    if (connection.is_connected()):
        cursor.close()
        connection.close()
        print("MySQL connection is closed")

【问题讨论】:

    标签: python mysql pcf


    【解决方案1】:

    如果您担心 mysql 凭据,那么您可以简单地创建一个服务密钥,它会显示所有详细信息...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 2015-06-24
      • 2015-10-02
      • 2014-09-18
      • 1970-01-01
      相关资源
      最近更新 更多