import pandas as pd
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=RONSQLEXPRESS;'
'Database=test_database;'
'Trusted_Connection=yes;')
df = pd.read_sql_query('SELECT * FROM products', conn)
print(df)
print(type(df))
#create database in python with mysql
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword"
)
mycursor = mydb.cursor()
mycursor.execute("CREATE DATABASE mydatabase")
import pyodbc
cnxn = pyodbc.connect(DRIVER='{SQL Server}',SERVER='***server ip address**',DATABASE='**cataloguename**',UID='**myusername**',PWD='**mypassword**')
cursor = cnxn.cursor()
import sqlite3
try:
sqliteConnection = sqlite3.connect('test.db')
cursor = sqliteConnection.cursor()
print("SQLITE Connection Established!")
cursor.close()
except sqlite3.Error as error:
print("Error while connecting to sqlite", error)
finally:
if (sqliteConnection):
sqliteConnection.close()
print("Connection closed")
# C:UsersYour NameAppDataLocalProgramsPythonPython36-32Scripts>python -m pip install mysql-connector-python
# Or you can refer the page: https://thietkewebhcm.com.vn/ket-noi-python-voi-sql-server/