I am using Python 3.4 from the Anaconda distribution. As part of this distribution, I found the pymysql library to connect to an existing MySQL database, which is located on another computer.
import pymysql config = { 'user': 'my_user', 'passwd': 'my_passwd', 'host': 'my_host', 'port': my_port } try: cnx = pymysql.connect(**config) except pymysql.err.OperationalError : sys.exit("Invalid Input: Wrong username/database or password")
Now I want to write test code for my application in which I want to create a very small database in the setUp each test case, preferably in memory. However, when I try to do this in blue using pymysql , it cannot establish a connection.
def setUp(self): config = { 'user': 'test_user', 'passwd': 'test_passwd', 'host': 'localhost' } cnx = pymysql.connect(**config) pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 61] Connection refused)")
I searched for search queries and found something about SQLite and MySQLdb . I have the following questions:
- Is
sqlite3 or MySQLdb suitable for quickly creating a database in memory? - How to install
MySQLdb in Anaconda package? - Is there an example test database created in
setUp ? Is that even a good idea?
I do not have a MySQL server running locally on my computer.
source share