I am using ActiveState Python 3 on Windows and wanted to connect to my MySQL database.
I heard that mysqldb
was the module to use.
I can't find mysqldb
for Python 3.
Is there a repository available where the binaries exist for mysqldb
?
How can I connect to MySQL in Python 3 on Windows?
Enter mysql.exe -uroot -p , and MySQL will launch using the root user. MySQL will prompt you for your password. Enter the password from the user account you specified with the –u tag, and you'll connect to the MySQL server.
There are currently a few options for using Python 3 with mysql:
https://pypi.python.org/pypi/mysql-connector-python
https://pypi.python.org/pypi/pymysql
MySQLdb
, after calling pymysql.install_as_MySQLdb()
https://pypi.python.org/pypi/cymysql
https://pypi.python.org/pypi/mysqlclient
python-mysqldb
andpython3-mysqldb
packages.benchmarks here: https://github.com/methane/mysql-driver-benchmarks
You should probably use pymysql - Pure Python MySQL client instead.
It works with Python 3.x, and doesn't have any dependencies.
This pure Python MySQL client provides a DB-API to a MySQL database by talking directly to the server via the binary client/server protocol.
Example:
import pymysql conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='root', passwd=None, db='mysql') cur = conn.cursor() cur.execute("SELECT Host,User FROM user") for r in cur: print(r) cur.close() conn.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With