How to use python 3.5.1 with a MySQL database

Awa Melvine

I have been trying to use MySQL in a Python project I've been working on. I downloaded the connector: mysql-connector-python-2.1.3-py3.4-winx64 here.

I already had Python 3.5.1 installed. When I tried to install the connector, it didn't work because it required python 2.7 instead. I have searched on many sites, even on StackOverflow I couldn't find a solution.

Thanks for any help.

S0H31L

I did the steps below with Python 3.5.1 and it works:

  • Download driver from here
  • Driver installation in cmd, in this folder Python\Python35\PyMySQL-0.7.4\pymysql

    python setup.py build
    python setup.py install
    
  • Copy folder Python\Python35\PyMySQL-0.7.4\pymysql to Python\Python35\pymysql

  • Sample code in python IDE

    import pymysql
    import pymysql.cursors
    conn= pymysql.connect(host='localhost',user='user',password='user',db='testdb',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
    a=conn.cursor()
    sql='CREATE TABLE `users` (`id` int(11) NOT NULL AUTO_INCREMENT,`email` varchar(255) NOT NULL,`password` varchar(255) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'
    a.execute(sql)
    
  • Enjoy It!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python class inheritance - how to use this to connect to a mysql database

From Dev

How to connected to existing MySQL database in Laravel 5?

From Dev

Which database to use with Django and Python 3?

From Dev

Which database to use with Django and Python 3?

From Dev

How to use Spring Boot with MySQL database and JPA?

From Dev

Mysql_query how to use it with a "dynamic" database?

From Dev

How to mysql database encrypt and use in Coldfusion

From Dev

Android: How to use an external MySQL database in an app

From Dev

How to use tensor-flow to reshape [1,2,3,4,5,6] into [[1,3,5],[2,4,6]]?

From Dev

How to copy a database with mysqldump and mysql in Python?

From Dev

How to insert Records of data into MySQL database with python?

From Dev

how to insert in mysql database using python

From Dev

How to query MySQL database using API in python?

From Dev

How to use use bind variables in mysql and python

From Dev

How to use use bind variables in mysql and python

From Dev

How to use use bind variables in mysql and python

From Dev

How to use python to query database in parallel

From Dev

How to use wxPython for Python 3?

From Dev

How to use cmp() in Python 3?

From Dev

How to use urllib in python 3?

From Dev

How to use slugify in Python 3?

From Dev

mysql database - statement to use?

From Dev

How to update a MySQL Database with UITextField content in Xcode 5?

From Dev

how to modify a database (mysql) and restore it after 5minutes?

From Dev

How to backup mysql database every 5 miniutes automatically

From Dev

How to drop a sqlite3 database in python?

From Dev

Python insert values <= 1e-7 in a MySQL database

From Dev

How to use Python 3 in Spyder 3?

From Dev

Check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATABASE$database' at line 1

Related Related

  1. 1

    Python class inheritance - how to use this to connect to a mysql database

  2. 2

    How to connected to existing MySQL database in Laravel 5?

  3. 3

    Which database to use with Django and Python 3?

  4. 4

    Which database to use with Django and Python 3?

  5. 5

    How to use Spring Boot with MySQL database and JPA?

  6. 6

    Mysql_query how to use it with a "dynamic" database?

  7. 7

    How to mysql database encrypt and use in Coldfusion

  8. 8

    Android: How to use an external MySQL database in an app

  9. 9

    How to use tensor-flow to reshape [1,2,3,4,5,6] into [[1,3,5],[2,4,6]]?

  10. 10

    How to copy a database with mysqldump and mysql in Python?

  11. 11

    How to insert Records of data into MySQL database with python?

  12. 12

    how to insert in mysql database using python

  13. 13

    How to query MySQL database using API in python?

  14. 14

    How to use use bind variables in mysql and python

  15. 15

    How to use use bind variables in mysql and python

  16. 16

    How to use use bind variables in mysql and python

  17. 17

    How to use python to query database in parallel

  18. 18

    How to use wxPython for Python 3?

  19. 19

    How to use cmp() in Python 3?

  20. 20

    How to use urllib in python 3?

  21. 21

    How to use slugify in Python 3?

  22. 22

    mysql database - statement to use?

  23. 23

    How to update a MySQL Database with UITextField content in Xcode 5?

  24. 24

    how to modify a database (mysql) and restore it after 5minutes?

  25. 25

    How to backup mysql database every 5 miniutes automatically

  26. 26

    How to drop a sqlite3 database in python?

  27. 27

    Python insert values <= 1e-7 in a MySQL database

  28. 28

    How to use Python 3 in Spyder 3?

  29. 29

    Check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATABASE$database' at line 1

HotTag

Archive