Django mysql connectio No module named mysql.base - mysql

I try to connect MySQL from django application serverd in AWS but it raises an interesting error: Error was: No module named mysql.base
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'try',
'USER': 'root',
'PASSWORD': 'pwd',
'HOST': '',
'PORT': '3306',
}
}
MySQLdb is already installed. import MySQLdb runs in python command line.
I can connect MySQL. I have installed it by sudo apt-get install mysql-server mysql-common mysql-client libmysqlclient15-dev
I am really stuck with this error. Could you help to figure this out?
Thanks

It seems to me that you haven't installed mysql for python.
http://pypi.python.org/pypi/MySQL-python/1.2.3
or
sudo apt-get install python-mysqldb

Seems like a problem with your Python PATH. Make sure the python-mysql db driver is in the PATH.

Related

django mysql not run in macOS Big Sur

Some trouble after Big Sur update
I use Django 2.1.15 and Python 3.8
according to posts and documentation I installed the connector
brew install mysql-connector-c
and
pip install mysql-python
after I install mysql
brew install mysql
and the client
pip install mysqlclient
try to run django and i get this ERROR:
django.db.utils.OperationalError: (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 54")
This is my setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'BATABASE',
'USER': 'sa',
'PASSWORD': 'password',
'HOST': '192.168.1.10',
'PORT': '1433',
}
}
You can try this https://github.com/imagineai/create-django-app
npm install -g imagine && imagine create -f django -n myapp
It will auto-detect your Python version and install appropriate dependencies. You can also select the database you want in the im file.

Can't get MySQL/MariaDB to work with Django 1.10.1 and Python 3.5 on Fedora 24?

Besides the above, I'm using virtualenv and virtualenvwrapper. MariaDB server 10.1.17 was installed via dnf install
I'm working through the first Django tutorial. My runserver command:
(djTut3)$ python manage.py runserver
ran OK, with a warning about migration.
In part 2, here: https://docs.djangoproject.com/en/1.10/intro/tutorial02/
I ran:
(djTut3)$ python manage.py migrate
as instructed, and got the following errors:
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
I did a lot of searching, and tried the below (among other things), mostly from SO:
===
$ sudo dnf install MySQL-python
<No error>
$ python3 manage.py migrate
<Same errors as before>
$ sudo dnf install mariadb-devel
Skipping packages with conflicts:
(add '--best --allowerasing' to command line to force their upgrade)
$ sudo dnf install mariadb-devel --best --allowerasing
<No error>
$ python3 manage.py migrate
<Same errors as before>
$ pip3 install mysql-python
ImportError: No module named 'ConfigParser'
$ pip3 install mysql-connector
<No error>
$ pip3 install mysql-client
_mysql.c:40:20: fatal error: Python.h: No such file or directory
#include "Python.h"
compilation terminated.
error: command 'gcc' failed with exit status 1
$sudo dnf install python-devel mysql-devel
<already installed>
===
Now I still can't get
(djTut3)$ python manage.py migrate
to work, and
(djTut3)$ python manage.py runserver
gives the same error as the migrate command.
My settings.py includes:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djTut3',
'USER': os.environ['DB_USERNAME'],
'PASSWORD': os.environ['DB_PASSWORD'],
'HOST': '127.0.0.1',
'PORT': '',
}
}
Can anyone offer some help with this?
Thanks very much in advance for any response.
This is why you should install Python packages via pip, not your OS package manager. MySQLdb is not available for Python 3, as you can see from the error when you tried via pip3.
The reason you had issues installing mysql-client is presumably because you need the python-devel package, or whatever the Fedora equivalent is; that would be a dnf install.
However since you did succeed with mysql-connector, you can use that; you need to configure Django to use it as shown in that library's documentation, by replacing 'django.db.backends.mysql' with 'mysql.connector.django'.

Can't migrate django databases on MySQL after upgrading to ubuntu 16.04

Reinstalled system on ubuntu 16.04 and when first trying to run python manage.py makemigrations got the following error:
django.db.utils.OperationalError: (1193, "Unknown system variable 'storage_engine'")
My django databases settings are:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'license_portal',
'USER': '****',
'PASSWORD': '****',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
"init_command": "SET storage_engine=MyISAM",
},
},
}
Libraries:
(mmslic) ➜ mmsLicenseServer git:(master) ✗ pip freeze
Django==1.8.12
django-admin-bootstrapped==2.5.7
django-bootstrap3==7.0.1
MySQL-python==1.2.5
mysqlclient==1.3.7
requests==2.9.1
(mmslic) ➜ mmsLicenseServer git:(master) ✗ dpkg -l | grep -i mysql
ii libmysqlclient-dev 5.7.12-0ubuntu1 amd64 MySQL database development files
ii libmysqlclient20:amd64 5.7.12-0ubuntu1 amd64 MySQL database client library
ii libmysqlclient20:i386 5.7.12-0ubuntu1 i386 MySQL database client library
ii libqt4-sql-mysql:i386 4:4.8.7+dfsg-5ubuntu2 i386 Qt 4 MySQL database driver
ii mysql-client-5.7 5.7.12-0ubuntu1 amd64 MySQL database client binaries
ii mysql-client-core-5.7 5.7.12-0ubuntu1 amd64 MySQL database core client binaries
ii mysql-common 5.7.12-0ubuntu1 all MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-server 5.7.12-0ubuntu1 all MySQL database server (metapackage depending on the latest version)
ii mysql-server-5.7 5.7.12-0ubuntu1 amd64 MySQL database server binaries and system database setup
ii mysql-server-core-5.7 5.7.12-0ubuntu1
After struggling with this issue I've found that the problem was a change on MySQL 5.7 version.
With MySQL 5.7 the command SET storage_engine=MyISAM won't work, so that was the problem!
As spotted on the MySQL 5.7 documentation use default_storage_engine instead! My configuration became:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'license_portal',
'USER': '****',
'PASSWORD': '****',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
"init_command": "SET default_storage_engine=MyISAM",
},
},
}

settings causing mysql to throw error

I have installed mysql in my virtual environment using this command and it has installed successfully..
sudo apt-get install libmysqlclient-dev
sudo pip install MySQL-python
Now in my settings.py I have done this..
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.path.join(BASE_DIR, 'db_hotelnepal'),
}
}
But when I run server it throws error saying ""Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb""...
Whats the prob and how can I fix ?
MySQL-python is not compatible with python 3, and it gives this error. You didn't mention the python version you are using, but I have only seen this when using python 3 and MySQL, so I will make that assumption. I use MySQL-for-Python-3 which can be found here: MySQL-for-Python-3. It is compatible with python 2.7-3.3, haven't had a project with MySQL and python 3.4 to try it yet.
I install by running pip install https://github.com/davispuh/MySQL-for-Python-3/archive/1.0.tar.gz

Problem running syncdb in django

I am trying to go through the django docs tutorial and having a problem syncing mysql. On the command python manage.py syncdb I get the following error (note I'm running in windows 7):
...
File "C:\python27\lib\site-packages\django\db\backends\mysql\base.py", line 14, in <module>
raise Improperlyconfigured("Error loading Mysqldb module: %s" % e)
django.core.excepions.Improperlyconfigured: Error loading Mysqldb module: No module named mySQLdb
I have initialized the db in setting.py as:
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mysite', #the name I gave in Mysql with 'CREATE DATABASE mysite;'
'USER': 'root',
'PASSWORD': 'mypassword', # as set in MysqlInstanceConfig
'HOST': '',
'PORT': '',
So how do I get syncdb to run correctly? What does the missing module error mean and how do I correct it?
You need to install the python mysql library.
Here is a django-related guide to do this on windows
You have to install the mySQLdb module.
You most probably haven't installed the Python module that handles the mysql connections. You can install it through the Cheeseshop with pip or easy_install and it's called MySQL-python.