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).
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) 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