installing mysql connector for python 3 in raspberry pi - mysql

I am new at using raspberry pi.
I have a python 3.4 program that connects to a database on hostinger server.
I want to install mysql connector in raspberry pi.I searched a lot but I was not able to find answers . any help would be appreciated

Before you install, it is important to run update and upgrade;
sudo apt-get update
sudo apt-get upgrade
Either install connector for Python 2;
sudo apt-get -y install python-mysql.connector
Or install connector for Python 3;
sudo apt-get -y install python3-mysql.connector

I found no way to install mysql-connector-python that I used with windows.
for python 3.4 I used the command
sudo python3 -m pip install pymysql
for python 2.7 you can use following commands
sudo apt-get install python-mysqldb
or
sudo apt-get install python-pip
pip install pymysql

Just use $sudo apt-get install python3-mysqldb and it works on pi-3.

Related

Linux Ubuntu 18.04 - Error loading MySQLdb module. Did you install mysqlclient?

I'm getting the following error message while running my Django REST project with MySQL database in pipenv.
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
This seems like a very common problem (please don't mark as duplication), but after trying all the possible solutions I'm still getting the same issue..
A few things I tried:
pip3 install mysqlclient
pip3 install python3.6-dev
pip3 install mysql-client
pip3 install libsqlclient-dev
pip3 install libssl-dev
What could still be the problem?
It's a Linux Ubuntu 18.04 server with Plesk. Python version 3.8.
mysqlclient has a dependency on the mysql client & dev packages being installed. In order to fix this on ubuntu, you have to use apt-get to install a couple of mysql packages.
In your case, it looks like the missing mysql_config might be missing on your system. You can fix that by installing libmysqlclient-dev on ubuntu bionic.
another way
install the follwing packages.
sudo apt-get install python3.8-dev
sudo apt-get install mysql-client
sudo apt-get install libsqlclient-dev
sudo apt-get install libssl-dev
other method
pip install pymysql
Then, edit the init.py file in your project origin dir(the same as settings.py)
add:
import pymysql
pymysql.install_as_MySQLdb()
You should install libmysqlclient-dev: sudo apt-get install libmysqlclient-dev
I had to install this.
sudo apt install libpython3.8-dev
Now it works.

Installing workbench on ubuntu

I am trying to install MySQL Workbench on Ubuntu 20.04, and I run these commands:
sudo apt-get update && sudo apt-get upgrade
sudo apt install mysql-workbench
the error is:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mysql-workbench
I used this way to install before but now I do not know what to do, please help, I am new in Ubuntu.
try this:
download snapd service using apt-get
sudo apt-get install snapd
after that install workbench
sudo snap install mysql-workbench-community
when it's done You need to enter a command to allow this package to access the service. The command is:
sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service
You have to add the repository in your source.list file:
echo "deb http://repo.mysql.com/apt/ubuntu/ eoan mysql-tools" | sudo tee /etc/apt/sources.list.d/mysql.list
then:
sudo apt update
sudo apt install mysql-workbench-community
MySQL has updated their repository for Focal Fossa and removed the repository for Eoan Ermine. To install MySQL Workbench on 20.04, either download the Workbench for 20.04 from MySQL archives or follow the alternate method mentioned below replacing eoan with focal.
Refer this:
https://askubuntu.com/questions/1230752/mysql-workbench-not-supporting-with-ubuntu-20-04-lts

how to install pyaudio module in google cloud shell?

Error:
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
I tried all of these commands:
sudo pip install pyaudio,
sudo apt-get install python-pyaudio ,
sudo pip install pyaudio ,
sudo pip install --upgrade pyaudio.
First, undo what you have done.
Then try to install it following their documentation for Debian based versions:
$ sudo apt install portaudio19-dev python-all-dev
followed by
$ sudo apt install python-pyaudio for python 2 version
OR
$ sudo apt install python-pyaudio for python 3 version.

Can't install mysql in raspberry pi

I am trouble installing mysql, I have this broken package return on installing mysql error.
This is what tutorial I followed below:
and this is the result
EDIT1:
I followed Sebastian Dixon's answer
Before you install, it is important to run update and upgrade;
sudo apt-get update
sudo apt-get upgrade
then:
sudo apt-get install mysql-server nginx
Hope this helps.

How should MySQL be installed in a Django application?

I am developing a project based on Django and MySQL on Ubuntu. I am a little confused about how MySQL should be installed. Should it be installed into the virtual environment or should it be installed into the system:
(a) To install MySQL in the virtual environment (python2Venv is the directory of the virtual environment):
$ sudo apt-get install libmysqlclient-dev
$ source <python2Venv>/bin/activate
(python2Venv)$ pip install MySQL-python
(b) However, according to the installation guide about MySQL, I have to do (https://help.ubuntu.com/12.04/serverguide/mysql.html):
$ sudo apt-get install mysql-python
$ sudo apt-get install mysql-server
Questions:
Is the above steps correct? Are both (a) and (b) necessary, or one of them is enough (maybe with additional setups)?
Fisrt, there is no mysql-python under Ubuntu/Debian repositories, the package is python-mysqldb and is an interface to the Mysql Server for python, is the driver for python and is needed to your Django project to work with Mysql.
Under pypi repository is named MySQL-python
Second, there is no reason to install a Mysql Server in a Python virtualenv, the Python virtualenv is for Python libraries/modules/frameworks, Mysql Server is not that.
So you can install the Mysql Server in your Ubuntu system by the official repository
apt-get install mysql-server
And then you can install all that python libraries that you need in your special python virtualenv for your Django project.
source ~/.virtualenv/<project-name>/bin/activate
pip install Django
pip install MySQL-python
to install mysql server:
sudo apt-get install mysql-server
now to install mysql-python in virtual env:
pip install MySQL-python
note: both pip install MySQL-python & apt-get install python-mysqldb are same.
MySQL driver for Python (mysql-python) needs libmysqlclient-dev. You can get it with:
sudo apt-get update
sudo apt-get install libmysqlclient-dev
If python-dev is not installed, you may have to install it too:
sudo apt-get install python-dev
Now you can install MySQL driver:
pip install mysql-python
Here is a complete installation guide for setting up Django to use MySQL on a virtualenv:
http://codex.themedelta.com/how-to-install-django-with-mysql-in-a-virtualenv-on-linux/