Using pythonanywhere's MySQL DB in python - mysql

I've created a MySQL DB on pythonanywhere.com. Now I'm writing a python script on my local PC trying to connect to it, but can't establish a connection.
import pyodbc
with pyodbc.connect(DRIVER="{MySQL ODBC 8.0 Unicode Driver}",
SERVER="******.mysql.pythonanywhere-services.com",
DATABASE="******$default",
USER="******",
PASSWORD="******",
OPTION="3") as conn:
cursor = conn.cursor()
Same with this connection string format:
pyodbc.connect("""DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=******.mysql.pythonanywhere-services.com;DATABASE=******$default;USER=******;PASSWORD=******""")
****** = censored username and password
It returns this error:
pyodbc.Error: ('HY000', "[HY000] [MySQL][ODBC 8.0(w) Driver]Can't connect to > MySQL server on '******.mysql.pythonanywhere-services.com' (10060) (2003) (SQLDriverConnect); [HY000] [MySQL][ODBC 8.0(w) Driver]Can't connect to MySQL > server on '******.mysql.pythonanywhere-services.com' (10060) (2003)")
The official documentation doesn't seem to tackle this problem. It only mentions the library mysqlclient but I can't find out what it's purpose is.
Edit: It's only possible via ssh/paid account Accessing your MySQL database from outside PythonAnywhere

Found the answer on the site. It's only possible via ssh/paid account Accessing your MySQL database from outside PythonAnywhere

Related

MySQL Workbench 8.0.26 data export SSL connection error 2026

I'm using MYSQL Workbench version 8.0.26 in my server dump in version 5.6.10. I already have the option in the Manage Server Connection "Use SSL = NO", but whenever i connect into it and try to EXPORT DATA, the process fails and the following error is presented:
mysqldump: Got error: 2026: SSL connection error: error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol when trying to connect
Already tried to reinstall or disabling the SSL again, but no success, still the same error, does anyone have any clue what can it be?

DatabaseError using SQLalchemy when trying to use engine to connect to MySQL server

I have a local MySQL server inside a Docker container. This container is from the "mysql/mysqlserver" image and is set to port 3306. I'm trying to connect to this server using the SQLalchemy library so that I can manipulate the database using Python, however it returns a database error when I try to use the engine object to access the database.
The code I'm using to create the engine is:
def mysql_engine_generator():
return create_engine("mysql+mysqlconnector://root:XXXXX#localhost:3306/mysql", echo=True)
engine = mysql_engine_generator()
And then I try to execute a simple SQL statement like so:
with engine.connect() as conn:
conn.execute(text("CREATE TABLE some_table (x int, y int)"))
Which gives me the following error:
DatabaseError: (mysql.connector.errors.DatabaseError) 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (111)
(Background on this error at: https://sqlalche.me/e/14/4xp6)
I went to the link indicated in the error message and It tells me the error must be in the dialect or the database driver, not in SQLalchemy itself. However, I'm using the driver and dialect combination recommended by the official MySQL documentation, so I have no idea how that could be wrong.
I tried manipulating the database using the MySQL CLI. The command "mysql> CREATE TABLE some_table (x int, y int)" worked just fine and the table was properly created, which tells me there was nothing wrong with the SQL statement or with the database itself.
I tried using "mysqldb" instead of "mysqlconnector" thinking it may the correct driver here. It gave me an operational error instead of the Database error:
OperationalError: (MySQLdb.OperationalError) (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)
I also tried using the "pymysql" driver, which gave me the fellowing error:
OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
(Background on this error at: https://sqlalche.me/e/14/e3q8)

[MySQL][ODBC 5.3(a) Driver]Can't connect to MySQL server

I have difficulty connecting to MySQL server from Tableau Server.
The error message is:
[MySQL][ODBC 5.3(a) Driver]
Can't connect to MySQL server on XYZ.
Unable to connect to the MySQL server "xyz".
Check that the server is running and that you have access privileges to the requested database
I have installed MySQL ODBC 5.3 Driver from tarball distribution in Ubuntu OS, and whitelisted the IP address of Tableau server in MySQL server.
What could be the possible causes for this? And is there any way that I check the ODBC connector was properly installed?
Any suggestion/comments are much appreciated!
Reasons, you could not connect could be different. But the error you've get asks you to check if server is running. It means, it could not find server.
The reasons, it could not find server, could be:
Server is down (Check its status by systemctl status mysql)
Server is not listening on some port your app connects to
Server is behind firewall (sudo ufw allow mysql command execution required to solve it in this case)
Your user does not have permissions to access that database, as it states in the error

ERROR 2027 (HY000): Malformed packet - during login

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -u root -p
Enter password:
ERROR 2027 (HY000): Malformed packet
I have 2 MySQL DBs version on my server 4.0 and 5.7. My apps can connect to both MySQL DBs without problem but when I try to login to the MySQL Command-Line Tool it is showing error as shown below. I also noticed even when I stopped the MySQL 5.7 service it is showing the same error but if I stopped the MYSQL4.0 service, it is showing:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
Based on the some of the replies from similar topics, the malformed packet is because of the old password hashed issue but what are the things I need to do to change the password? Or my issue is not related with password?
FYI, I am using Windows Server 2012 R2. Mysql 5.7.21 and Mysql 4.0.17
It's compatibility issue between MySQL 5.7 client and MySQL 4.0 server.
My apps can connect to both MySQL DBs without problem but when I try to login to the MySQL Command-Line Tool it is showing error as shown below.
The reason may be simple, apps may be using diffrent version of Mysql connector API, e.g. App connect with v5.7 may be using 5.7 compatible liberary.
When you connect to MySQL 4.0, use MySQL 4.0 client and similar for MySql 5.7.
When you run both version simultaneously, make sure to specify the correct port.

mySQL command line works but ODBC and workbench do not

I am trying to test a connection to a mySQL database running on a remote linux server. I am running Windows 7 and have mySQL installed on my machine as well as the 32-bit ODBC driver. I can connect from the DOS command prompt with no problems. But I cannot connect using mySQL workbench or with ODBC (from MS Access).
In MySQL workbench my error is:
Your connection attempt failed for user 'username' from your host to server at 'x.x.x.x:x': Unknown MySQL server host 'x.x.x.x' (0)
In MS Acess (ODBC driver) my error is:
Connection faile:[HY000][MySQL][ODBC 5.2(w) Driver]Can't connect to MySQL server on 'x.x.x.x' (10061)
I've searched stackoverflow extensively and I found lots of people who can't get ANY connection to work. But I know I can log in from my computer. Could it be something other than ports?
Please make sure you are using correct ip address in MySQL workbench to connect to your mysql database