0

I was given some credentials, but I appear to be missing something here, as the script errors out when trying to make a connection.

import mysql.connector

def test_sql_query():
    db = mysql.connector.connect(host='hostname', database='db', user='dbuser,' password='dbpass', port='000')
    cur = db.cursor()
    if db.is_connected():
        print('Connected to MySQL database')
    try:
        sql_command = "select * from test where test like '%FileUploadAgent%' and status='00' order by test desc;"
        cur.execute(sql_command)
        db.commit()
        rows = cur.fetchall()
        for row in rows:
            print "   ", row[1][1]
    except:
        print "did not work"
    db.close()

I was provided with the following credentials: host, user, passwd, driver, jdbc.url, port

In my sql script there is nowhere that I am using driver or jdbc.url. What are these two things and are they required to make a database connection. Is this why I am unable to connect?

Ben
  • 519
  • 1
  • 7
  • 14

2 Answers2

0

You may need to check if the remote database is allowed to connect remotely.

How to allow remote connection to mysql

Community
  • 1
  • 1
Vinod K
  • 148
  • 2
  • 16
0

this line is missing comma:

db = mysql.connector.connect("host='hostname' database='db' user='dbuser' password='dbpass' port='000'")

replace to

db = mysql.connector.connect(host='hostname', user='dbuser', passwd='dbpass', db='db')
  • sorry that was a typo, i corrected the OP, i still can't establish the db connection though. – Ben Jun 06 '16 at 19:38
  • look the comma in this line: mysql.connector.connect(host='hostname', database='db', user='dbuser,' password='dbpass', port='000') - in dbuser is wrong place – Juliana Skubs Jun 06 '16 at 19:47