Home > Backend Development > Python Tutorial > How to connect python to mysql database under ubuntu system

How to connect python to mysql database under ubuntu system

高洛峰
Release: 2017-01-10 13:45:09
Original
1282 people have browsed it

Enter root permissions

apt-get install mysql-server
apt-get install mysql-client
Copy after login

Create database

mysql -u root -p passward 链接数据库
create database basename
use basename
Copy after login

If the database exists and you want to make changes, you can use it directly

mysql -u root -p passward basename
Copy after login


Create table

create table latest_face( id int(11) not null auto_increment, camera_id varchar(240) not null, picture mediumblob not null, datetime datetime not null, people_id int(11) not null, people_name varchar(16),accessed int(4) not null,primary key(id) )charset = gb2312;
Copy after login

Use python to connect to the database.

When using apt-get install mysql-python, it will prompt that the software package mysql-python is not found. However, it is very troublesome to download and install directly, so I used pip install mysql-python

When using pip install mysql-python, it prompted EnvironmentError: mysql_config not found. At this time, reinstall libmysqlclient-dev, pt-get install libmysqlclient-dev, and then pip install mysql-python. The installation is successful

Enter import MySQLdb under python to test whether it can be used

The above The above is the method of python linking mysql database under the ubuntu system introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!

For more related articles on how to link mysql database with python under ubuntu system, please pay attention to PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template