I am sure you could google this
but here's what I've done in the past

1) file 1 has the login info.
   I make it to prompt for user's password
   (you could hardcode the password in this file)

import getpass

USERNAME = "yourusername"
DBNAME   = "yourdatabasename"
PASSWORD = getpass.getpass("Enter password for database {0}: ".format(DBNAME))

login_info = {
               'host'     : "your.sql.server.domain.name",
               'user'     : USERNAME,
               'password' : PASSWORD,
               'database' : DBNAME,
               'port'     : yoursqlport,
             }

2) file 2 has the SQL code

import mysql.connector
from file_1_above import login_info

db = mysql.connector.Connect(**login_info)
cursor = db.cursor()


>From here on, you use "cursor" to operate on your database.


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to