- install mysql-connector-python
$ sudo pip3 install --extra-index-url https://pypi.python.org/pypi/mysql-connector-python/2.0.4 mysql-connector-python
- 本地开启mysql数据库,在terminal中输入python3,导入模块并创建连接
>>> import mysql.connector >>> conn = mysql.connector.connect(user='root', password='mysql', database='engineer') >>> cursor = conn.cursor() >>> cursor.execute('select * from user') >>> values = cursor.fetchall() >>> values [('1', '1', '1', '1'), ('2', '2', '2', '2')] >>> cursor.close() --关闭游标 True >>> conn.close() --关闭连接
相关文章
- 05-10Error connecting to database [Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)]
- 05-10Writing to a MySQL database from SSIS
- 05-10Guide to Database Migration from Microsoft SQL Server using MySQL Workbench
- 05-107.1 Connecting to a MySql database from Python
- 05-10How can I move a MySQL database from one server to another?