2

I created the my own database in azure which is now doesn't have any data. I follow this documentation to create the DB. I want to create table and access it from my machine using python. Here what I tried so far

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)

but when I when i run it its throwing the following error

9002 (28000): The server name you tried cannot be found: <servername>.database.windows.net. Please check the Username and retry connection. The Username should be in <username@hostname> format.

I filled the credentials with mine.

Thanks in advance

I can access from Microsoft SQL Server Management Studio

Why I can't access via Python?

2

1 Answer 1

2

I think you misunderstood SQL and MySQL. You can check here the difference between them.

You are trying to access the SQL database using MySQL connector. That can't be done. You have two solutions here

  1. change your DB to MySQL check here
  2. access using SQL code check here

feel free to ask if you need any clarification

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.