Home > Article > Backend Development > How to connect python to mysql database under ubuntu system
Enter root permissions
apt-get install mysql-server apt-get install mysql-client
Create database
mysql -u root -p passward 链接数据库 create database basename use basename
If the database exists and you want to make changes, you can use it directly
mysql -u root -p passward basename
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;
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!