Hi i am using python and database as Mysql, Now i want to connect to Mysql database from python and i wrote the below code

Method_1

import MySQLdb as mdb


conn = mdb.connect('ip_address', 'user_name', 'pass_word', 'database_name') 

By using above i can connect to Mysql succesfully, but i want to know whether we can do the same by using a connection string and accessing like i mentioned below

Method_2

connectString=Server=ip_address;Database=database_name;UID=user_name;PWD=pass_word
conn = mdb.connect(connectString) 

But i am getting an error by using above, so can anyone let me know whether we can access Mysql database only by method_1 or is there any way to declare the access credentials to some variable and using that variable to connect as i mentioned in method_2

Edited Code:

Actually what i am trying is given below

example_file.ini

[for_primary]

connectString=host="192.168.xx.xxx",user="username_1",passwd="password_1",db="database_1"

[for_secondary]

connectString=host="192.168.xx.xxx",user="username_2",passwd="password_2",db="database_2"

file.py:

import ConfigParser
import MySQLdb as mdb

configFeed = ConfigParser.ConfigParser()
configFeed.read('path to file/example_file.ini')
connectString = configFeed.get('for_primary', 'connectString')
conn = mdb.connect(connectString)
print conn

Result:

 File "/usr/lib64/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2005, 'Unknown My
Edit
Report