I've recently installed the official MySQL extension for Python. However, when connecting to the server it asks me to select the database, but I have not made a database yet.
I don't really know what to do here. So I tried to connect using my information without the database but received errors with the following code:
import mysql.connector
cnx = mysql.connector.connect(user='ubuntulogin', password='ubuntupassword',
host='localhost')
cursor = cnx.cursor()
query = ("CREATE DATABASE database")
cursor.execute(query)
cursor.close()
cnx.close()
Please let me know any issues with my code or how to get MySQL information when I don't know mydatabase name.
Thanks
EDIT: My error message when running the code was:
File "/home/liam/sqltest.py", line 3, in <module>
cnx = mysql.connector.connect(user='ubuntulogin', password='ubuntupassword', host='localhost')
File "/usr/lib/python2.7/dist-packages/mysql/connector/__init__.py", line 162, in connect
return MySQLConnection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 129, in __init__
self.connect(**kwargs)
File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 454, in connect
self._open_connection()
File "/usr/lib/python2.7/dist-packages/mysql/connector/connection.py", line 417, in _open_connection
self._socket.open_connection()
File "/usr/lib/python2.7/dist-packages/mysql/connector/network.py", line 475, in open_connection
errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (111 Connection refused)