How to connect superset with mysql database? - mysql

I was trying to connect superset with mysql database with this SQLAlchemy URI:mysql://localhost:3306/mysql/database/table1 but not able to connect.
I was getting this error:
ERROR: {"error": "Connection failed!
The error message returned was:
No module named 'MySQLdb'", "stacktrace": "Traceback (most recent call last):
File \"/Users/akay/venv/lib/python3.7/site-packages/superset/views/core.py\", line 1703, in testconn
engine = database.get_sqla_engine(user_name=username)
File \"/Users/akay/venv/lib/python3.7/site-packages/superset/utils/core.py\", line 131, in __call__
value = self.func(*args, **kwargs)
File \"/Users/akay/venv/lib/python3.7/site-packages/superset/models/core.py\", line 923, in get_sqla_engine
return create_engine(url, **params)
File \"/Users/akay/venv/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py\", line 479, in create_engine
return strategy.create(*args, **kwargs)
File \"/Users/akay/venv/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py\", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File \"/Users/arkay/venv/lib/python3.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py\", line 118, in dbapi
return __import__(\"MySQLdb\")
ModuleNotFoundError: No module named 'MySQLdb'
"}
Is there any way to connect to a MySQL database?

MySQLdb is not compatible with Python 3, You need to use pymysql.
Install pymysql:
$ pip install pymysql
Connect to mysql data source with below URI string.
mysql+pymysql://user:pass#host/databasename

Configure your database user with hostname=localhost

You need to install mysql-connector-python module:
$ pip install mysql-connector-python

Had similiar issue. I'm sure this will save time for some of you out there:
Use 127.0.0.1 instead of localhost.
Here is the perfect template for MySQL string:
SQLALCHEMY_DATABASE_URI = 'mysql://username:password#127.0.0.1:3306/schema-name'
Install MySQL:
pip3 install mysqlclient
Upgrade SQLAlchemy:
pip install sqlalchemy==1.3.24
Load DB:
superset db upgrade
Create Admin user:
superset fab create-admin

If you are using Docker try using host.docker.internal as host name. It worked for me

Related

mysql driver not loading on flask_sqlalchemy python3 in venv | No module named 'MySQLdb'

Im trying to make the following combination work.
No luck. Anyone here can help ?
flask_sqlalchemy
mysqlclient
mysql-connector-python
Python 3.9.5
setup.cfg has above package and being installed in a venv
Error
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'], echo = True)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi
return __import__("MySQLdb")
ModuleNotFoundError: No module named 'MySQLdb'
venv had to be resourced in a shell environment. So packages installed were not in path.
Also, mysql-connector-python is not required in the above setup.
So much steps for a local isolated package installation scope.
python3 -m venv venv
. venv/bin/activate
pip install -e .
cp .env to instance/
flask run

unable to install mysqlclient on mac

I'm attempting to install mysqlclient using the command:
pip install mysqlclient
but i get the following error:
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-ifu54299/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-ifu54299/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-ifu54299/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
I uninstalled python3 using brew uninstall --force python3 and downloaded the binary from pythons website but to no avail. I also attempted to download mysql connector from oracle website and again to no avail. I have tried upgrading pip again still doesnt work.
PS mysql is running in a docker container and i'm running django on my local machine.
Any suggestions on why i'm getting an error attempting to install mysqlclient
For Python I can recommend pymysql is pretty good and I always use it.
https://github.com/PyMySQL/PyMySQL
or you can follow this answer
Installing MySQL Python on Mac OS X
you need to install mysql and mysql connector before install my sql client
brew install mysql
brew install mysql-connector-c

MySQL (MariaDB) backend for Django under Python3 on Debian

I am attempting to configure Django running under Python3 on a Debian box to use MariaDB as its backend. If I alter my mysite/settpings.py as per the tutorial i.e.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'foo',
'USER': 'tim',
'PASSWORD': 'swordfish',
'HOST': 'localhost'
}
}
I get a lot of grief, culminating in
File "/usr/local/lib/python3.4/dist-packages/django/db/backends/mysql/base.py", line 30, in <module>
'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?
Now, obviously, MySQLdb doesn't work on Python3 and although I have installed the mysql connector package doesn't seem to work.
If I try using the connector recommended by MySQL
i.e.
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'foo',
'USER': 'tim',
'PASSWORD': 'swordfish',
'HOST': 'localhost'
then I get a load of grief culminating in
django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
Error was: cannot import name 'BaseDatabaseFeatures'
Any suggestions?
UPDATE
Further to Matt Seymour's suggestion if I attempt a pip (actually pip3 as my system Python is still 2.x) install of mysqlclient I get the following...
tim#merlin:~/mysite$ sudo pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-1.3.10.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-9uub69zo/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/tmp/pip-build-9uub69zo/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/tmp/pip-build-9uub69zo/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9uub69zo/mysqlclient
Could the fact that I am using MariaDB rather than MySQL be significant here?
OK, after some messing around I have an answer of sorts, although not as satisfactory as I would like.
The MySQLdb library isn't supported under Python 3.x, and so you should use the mysqlclient fork of it instead. However, because I am using the MariaDB fork of MySQL, some of Debian's dependencies required to install mysqlclient are unmet. I don't want to revert to MySQL as I am using MariaDB for other purposes.
So, as all I needed was a fairly robust, multi-user back-end RDBMS, I've installed PostgreSQL for use with Django which seems to work nicely enough.

Failed to clone an exist mysql server using mysqlserverclone utilities

I installed mysql server 5.7.12 utilities 1.5.6 using mysql installer for windows. I configed mysql-server through installer wizard. Then, I try to clone this server using mysqlcloneserver utilities:
mysqlserverclone --server=root:mysql#localhost:3306 --new-data="C:/Users/quyet/Documents/DBMS/fabric/store" --mysqld="--server-id=2 --log-bin --log-slave-updates --gtid-mode=ON --enforce-gtid-consistency" --new-port=13000 --delete-data
The command ouput this error after run the command:
WARNING: Using a password on the command line interface can be insecure.
# WARNING: Root password for new instance has not been set.
# Cloning the MySQL server running on localhost.
The console has detected that the utility 'mysqlserverclone' ended with an error code.
You can get more information about the error by running the console command 'show last error'.
I run command:
show last error
and get this output:
Execution of utility: 'mysqlserverclone --server=root:mysql#localhost:3306 --new-data=C:/Users/quyet/Documents/DBMS/fabric/store --mysqld=--server-id=2 --log-bin --log-slave-updates --gtid-mode=ON --enforce-gtid-consistency --new-port=13000 --delete-data' ended with return code '1' and with the following error message:
Traceback (most recent call last):
File "G:\ade\build\sb_0-16486154-1442332453.92\Python-2.7.6-windows-x86-32bit\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
File "scripts\mysqlserverclone.py", line 211, in <module>
File ".\mysql\utilities\command\serverclone.py", line 180, in clone_server
File ".\mysql\utilities\common\tools.py", line 254, in get_mysqld_version
IOError: [Errno 13] Permission denied: 'version_check'
I has searched on google but found any similar problems.
Any help will be much appreciated !
A bit outdated, but it might help.
Run Mysql Utils console as administrator

mysql-workbench on Slackware 13.37 KDE error

After many hours of installing various libraries on my Slackware 13.37 i managed to start mysql-workbench (but I was wrong).
When launched from command line i get this warning:
bash-4.2# mysql-workbench
** Message: Gnome keyring daemon seems to not be available. Stored passwords will be lost once quit
Traceback (most recent call last):
File "/usr/local/lib/mysql-workbench/modules/wb_admin_ssh.py", line 43, in <module>
import paramiko
ImportError: No module named paramiko
Warning! Can't use connect with timeout in paramiko None
Traceback (most recent call last):
File "/usr/local/lib/mysql-workbench/modules/wb_admin_grt.py", line 27, in <module>
import wb_admin_main
File "/usr/local/lib/mysql-workbench/modules/wb_admin_main.py", line 29, in <module>
import wb_admin_monitor
File "/usr/local/lib/mysql-workbench/modules/wb_admin_monitor.py", line 21, in <module>
import wba_monitor_be
File "/usr/local/lib/mysql-workbench/modules/wba_monitor_be.py", line 26, in <module>
import wb_admin_ssh
File "/usr/local/lib/mysql-workbench/modules/wb_admin_ssh.py", line 119, in <module>
log_warning(_this_file, 'Cannot use connect with timeout in paramiko version %s\n' % paramiko.__version__)
AttributeError: 'NoneType' object has no attribute '__version__'
** Message: Failed loading module '/usr/local/lib/mysql-workbench/modules/wb_admin_grt.py' (python)
Ready.
the main program window appear and when i try to make a new connection i get this error :
Traceback (most recent call last):
File "/usr/local/share/mysql-workbench/sshtunnel.py", line 14, in <module>
import paramiko
ImportError: No module named paramiko
** (mysql-workbench-bin:2919): WARNING **: Tunnel manager could not be executed
and a popup appears:
Failed to Connect to MySQL at 127.0.0.1:3306 with user root Cannot
start SSH tunnel manager
mysql and ssh is installed and configured correctly:
bash-4.2# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.24 MySQL Community Server (GPL)
bash-4.2# ssh -v
OpenSSH_6.0p1, OpenSSL 0.9.8x 10 May 2012
can someone help me please !!!
It tells you that the python-paramiko module is missing. It is a python module for SSH connections; apparently that is used by one of the MySQL Workbench features. Get the slackware package here and install it executing
sudo installpkg paramiko-1.7.6-noarch-1gds.txz
Good luck!
Good answer above. On 64 bit systems, you have to install specific 32 bit libraries for workbench to work. E.g I had to install 32 bit python alongside the 64 bit python.
Also common errors include distribution specific errors. "/etc/mysql/my.cnf" not found, I created a soft link from /etc/my.cnf. Also had to create a folder at /root/.mysql/workbench/log for workbench to launch