Search
 
SCRIPT & CODE EXAMPLE
 

SQL

python how to connect to sql server

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))
Comment

how to connect sql database in python

#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")
Comment

python connection to remote SQL server

import pyodbc
cnxn = pyodbc.connect(DRIVER='{SQL Server}',SERVER='***server ip address**',DATABASE='**cataloguename**',UID='**myusername**',PWD='**mypassword**')
cursor = cnxn.cursor()
Comment

connect to sql database python

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")
Comment

sql server in python

# 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/
Comment

PREVIOUS NEXT
Code Example
Sql :: create table sql server auto increment primary key 
Sql :: oracle nls parameters 
Sql :: list all tables and columns in postgresql 
Sql :: apex select list ORA-20999 
Sql :: mysql add comment to column 
Sql :: postgresql show owner of database 
Sql :: sql select column names 
Sql :: describe sql server 
Sql :: start mysql linux terminal 
Sql :: tsql rename table 
Sql :: create column mysql terminal 
Sql :: change month to name in sql server 
Sql :: sql server loop over query 
Sql :: mysql drop trigger 
Sql :: creating a view sql 
Sql :: sqlserver create table from select 
Sql :: woocommerce mysql price table 
Sql :: psql import backup file for windows 
Sql :: import .sql into postgres db command 
Sql :: having vs where 
Sql :: alter table 
Sql :: show tables sql 
Sql :: postgresql restore from dump 
Sql :: turn off safe mode mysql 
Sql :: if not exists insert sql 
Sql :: stop and start mysql 
Sql :: mysql error incompatible with sql_mode=only_full_group_by 
Sql :: psql datetime grather than 
Sql :: how to add unique key constraint in mysql 
Sql :: find tables with column name in sql 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =