Can';t使用python从我的计算机访问Azure SQL DB
我在azure中创建了我自己的数据库,现在它没有任何数据。我按照文档创建数据库。我想创建表并使用python从我的机器访问它。这是我迄今为止所尝试的Can';t使用python从我的计算机访问Azure SQL DB,python,azure,azure-sql-database,Python,Azure,Azure Sql Database,我在azure中创建了我自己的数据库,现在它没有任何数据。我按照文档创建数据库。我想创建表并使用python从我的机器访问它。这是我迄今为止所尝试的 import mysql.connector from mysql.connector import errorcode # Obtain connection string information from the portal config = { 'host': '<servername>.database.window
import mysql.connector
from mysql.connector import errorcode
# Obtain connection string information from the portal
config = {
'host': '<servername>.database.windows.net',
'user': '<username>@servername.database.windows.net',
'password': '<passwword>',
'database': '<DB name>'
}
# Construct connection string
try:
conn = mysql.connector.connect(**config)
print("Connection established")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with the user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
导入mysql.connector
从mysql.connector导入错误代码
#从门户获取连接字符串信息
配置={
“主机”:“.database.windows.net”,
“用户”:“@servername.database.windows.net”,
“密码”:“,
“数据库”:”
}
#构造连接字符串
尝试:
conn=mysql.connector.connect(**config)
打印(“建立连接”)
除了mysql.connector.Error作为错误外:
如果err.errno==errorcode.ER\u访问被拒绝\u错误:
打印(“用户名或密码有问题”)
elif err.errno==errorcode.ER\u BAD\u DB\u错误:
打印(“数据库不存在”)
其他:
打印(错误)
但是当我运行它时,它抛出以下错误
9002(28000):找不到您尝试的服务器名称:.database.windows.net。请检查用户名并重试连接。用户名的格式应为。
我用我的证书填好了
提前谢谢
我可以从Microsoft SQL Server Management Studio访问
为什么我不能通过Python访问?我想你误解了
SQL
和MySQL
。您可以检查它们之间的差异
您正在尝试使用MySQL
连接器访问SQL
数据库。那是不可能的。这里有两种解决方案
MySQL
checkSQL
代码检查进行访问请随时询问您是否需要任何澄清您是否正在使用或?两者都不一样!您的代码是针对MySQL的,但您提到您遵循了for SQL创建数据库的步骤。很可能这就是问题所在。代码应该是针对SQL的。如果你想要MySQL,那么就改为创建MySQL。创建数据库后,你设置了防火墙规则吗?