Python MySQLd under Ubuntu

Any slightly more complicated website cannot do without data exchange with data. When developing with Django, you need to configure the database. When you choose the mysql database, if you want django and mysql to successfully "communicate" and exchange data, you need a bridge. ——MySQLdb, after upgrading the computer's ubuntu system the night before (from 14.04LTS version to 16.04LTS), the previous project on the computer then reported an error after executing the python manage.py runserver command. The error message was django.core.exceptions. ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient.so.18: cannot open shared object file: No such file or directory.

Then Baidu looked for a solution, including finding a solution on Stackoverflow. Most articles said that MySQLdb might not be installed, and then I went to install MySQLdb, but the system reminded that it has been installed, and the reminder message is as follows: Requirement already satisfied (use --upgrade) to upgrade): MySQL-python==1.2.3 in /usr/local/lib/python2.7/dist-packages

This means that there is MySQL-python in the system, but why does it report an error? After thinking about it for a long time, then I thought of uninstalling and reinstalling, and then the problem was solved (haha, artifact, in fact, I didn't understand why this is, it may be related to the system, after upgrading the system, some previous things may not be good Used).

I have encountered many problems when installing MySQLdb on the previous ubuntu 14.04LTS version. I will summarize here today. These are the problems I usually encounter, and I may encounter more in the future. Slowly add them as needed. Friends can refer to the following (the irregularities, but also hope to give me advice).

  1. MySQLdb installation

Installation is very simple. If you have the three major artifacts of pythoneer, virtualenv, fabric and pip (if you are a python developer, install it at the end, these three tools are really powerful. There are installation methods on the Internet, not here. Introduction), the installation of MySQLdb is very simple, and one command can be solved.

pip install MySQL-python

If you want to specify the version, you can do this

pip install MySQL-python==1.2.3

If you can't install it (the premise is to ensure that pip is installed successfully and can be used), it may be a permission problem. At this time, add sudo before pip.

But, do you think this is all right? This may be fine under windows system, but not under ubuntu system. It needs some dependency packages. The installation command is as follows:

sudo apt-get install mysql-client 
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev

Then import MySQLdb, if no error is reported, the installation is successful

  1. Common problems in executing python manage.py runserver

(1) Error: mysql_config not found

Solution: Install the mysqld-dev package, the installation command has

(2) Error: _mysql.c:2810: error: expected declaration specifiers before'init_mysql'

Solution: install python-dev

(3) Error: ImportError: No module named setuptools

Solution: install setuptools

sudo apt-get install python-setuptools

(4) Error 1193, "Unknown system variable'storage_engine'

It may be related to django's database configuration or mysql configuration file,

Add a sentence in the database configuration:

' OPTIONS': {
            'init_command': 'SET default_storage_engine=INNODB',
        },

You can solve the problem.

After MySQL5.5, the default database storage engine is innod, I use version 5.7, and my previous configuration is

' OPTIONS': {
                    'init_command': 'SET storage_engine=MyISAM',  
        },

So there will be an error, so there are two ways to modify, one is to change the django setting file, the other is to change the mysql configuration file etc/mysql/my.cnf, add a sentence SET default_storage_engine=MyISAM, but no matter how you change it, both It should be consistent.

Recommended Posts

Python MySQLd under Ubuntu
Install python3.6 under Ubuntu 16.04
[python] python2 and python3 under ubuntu
Python Chinese encoding setting under ubuntu
ubuntu18.04 install python2
Relearn ubuntu --python3
ubuntu12.04 install python3
ubuntu18.04 install python
ubuntu16.04 upgrade python2
Build a python development environment under Ubuntu
Ubuntu18.04 switch Python version
Install apache+PHP under Ubuntu
ubuntu configuration python, Red
Install mysql under Ubuntu 16.04
Install Thrift under ubuntu 14.10
Install OpenJDK10 under Ubuntu
Install Caffe under Ubuntu 14.04
Ubuntu16.04 switch python version
Start working under ubuntu
Use iptables under ubuntu
2018-09-11 Install arduino under Ubuntu
Install Python3 on Ubuntu 14.04
LNMP installation under Ubuntu
Network configuration under Ubuntu
Python virtual environment: Ubuntu16.04
Install python in Ubuntu
Install Python3 on Ubuntu 16.04
Install ROS under ROS Ubuntu 18.04[2]
Install MySQL under Ubuntu
Install Yarm-PM2 under Ubuntu
Install Python3.7 on Ubuntu
Installation and use of GDAL in Python under Ubuntu
Django&MySQL environment deployment under Ubuntu 14.04
Deploy FTP server under ubuntu
Ubuntu install the latest Python 3.
Install python environment under Linux
Install Python 3.7 on Ubuntu 18.04 LTS
ubuntu sets python2.5 environment variables
ubuntu18.04 compile and install python3.8
Solve Unment dependencies under ubuntu
ubuntu view python installation path
Open SSH service under Ubuntu
Use sublime tex under ubuntu
Modify shortcut keys under Ubuntu 18.04
Python script writing under SecureCRT
Use of mediawiki under ubuntu
Install server-side Shadowsocks under Ubuntu 16.04
Open SSH service under Ubuntu
DNS service construction under Ubuntu
ubuntu build python development environment
ubuntu offline installation python environment
Install rgl package under Ubuntu
Detailed steps for installing Django under Python 3.6 in Ubuntu 16.04 environment
Use QQ under Ubuntu 13.10, suitable for 14.10
Installation of deb package under Ubuntu
Deploy the mail system under Ubuntu 19.10
How to compile ijkplayer-android under ubuntu
Install 3 single-cell R packages under Ubuntu
How to install Python 3.8 on Ubuntu 18.04
Install and deploy Gerrit under Ubuntu
Install MySQL under Ubuntu 18.04 (graphic tutorial)