Forums

Is MySQL Connector Supported by PA?

Note: I have an unpaid account

I keep getting this error when trying to connect through my connect.py file: " 1044 (42000): Access denied for user 'g**'@'%' to database 'e****' "

I thought it might be a result of granting privileges, but running this didn't work either: -mysql -h ..... -u ..... -p -GRANT ALL PRIVILEGES ON . TO 'g**'@'%' IDENTIFIED BY 'password';

I think that you may be using the wrong name for the database. Databases on PythonAnywhere start with your username, then a dollar sign -- for example, giroday$something, not just something.

If you are trying to connect to an external database (not hosted on PythonAnywhere), then it won't work since you have an unpaid account, which restricts your code from accessing most sites.

I see. I have access to create databases prefixed by "giroday$", e.g. giroday$something

thanks!

I see. I have access to create databases prefixed by "giroday$", e.g. giroday$something

thanks!

Yes, that's right -- you only need to type the something into the database creation form on our website, but you do need to use the extra yourusername$ at the start when accessing your database from your code or from a MySQL console.

Hlw! I am trying to use mySQL python Connector in pythonanywhere the simple code is:

import mysql.connector as mysql
db = mysql.connect(host="LalitDumka.mysql.pythonanywhere- 
services.com",user="LalitDumka",password='ktrhpdkn')
cursor = db.cursor()
cursor.execute(f"create database if not exists \"LalitDumka$lakshit\" ")
cursor.commit()
db.close()

but when i run it, it shows the error-

Traceback (most recent call last):
  File "/home/LalitDumka/.virtualenvs/LXDPP/lib/python3.7/site-packages/mysql/connector/connection_cext.py", line 489,
 in cmd_query
    raw_as_string=raw_as_string)
_mysql_connector.MySQLInterfaceError: You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near '"LalitDumka$lakshit"' at line 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    cursor.execute(f"create database if not exists \"LalitDumka$lakshit\" ")
  File "/home/LalitDumka/.virtualenvs/LXDPP/lib/python3.7/site-packages/mysql/connector/cursor_cext.py", line 266, in 
execute
    raw_as_string=self._raw_as_string)
  File "/home/LalitDumka/.virtualenvs/LXDPP/lib/python3.7/site-packages/mysql/connector/connection_cext.py", line 492,
 in cmd_query
    sqlstate=exc.sqlstate)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that cor
responds to your MySQL server version for the right syntax to use near '"LalitDumka$lakshit"' at line 1

PLZZ HELP I've Tried a lot but nothing is happening

You don't have the permissions to create a database from your SQL code -- the only way you can create one is from the "Databases" page inside PythonAnywhere.

(The reason that you're getting the error is that you would need to use `` characters to quote the database name, not"`, but if you fixed that you'd still just get a permission error.)

Traceback (most recent call last): File "/home/bipins8671/mysite/flask_app.py", line 2, in <module> db = mysql.connect(host="bipins8671.mysql.pythonanywhere-services.com",user="bipins8671",password='bipinsingh') File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/init.py", line 179, in connect return MySQLConnection(args, kwargs) File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 95, in init self.connect(*kwargs) File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/abstracts.py", line 716, in connect self._open_connection() File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 208, in _open_connection self._do_auth(self._user, self._password, File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 144, in _do_auth self._auth_switch_request(username, password) File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 177, in _auth_switch_request raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'bipins8671'@'10.0.0.206' (using password: YES)

Traceback (most recent call last): File "/home/bipins8671/mysite/flask_app.py", line 2, in <module> db = mysql.connect(host="bipins8671.mysql.pythonanywhere-services.com",user="bipins8671",password='bipinsingh') File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/init.py", line 179, in connect return MySQLConnection(args, kwargs) File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 95, in init self.connect(kwargs) File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/abstracts.py", line 716, in connect self._open_connection() File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 208, in _open_connection self._do_auth(self._user, self._password, File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 144, in _do_auth self._auth_switch_request(username, password) File "/home/bipins8671/.local/lib/python3.10/site-packages/mysql/connector/connection.py", line 177, in _auth_switch_request raise errors.get_exception(packet) mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'bipins8671'@'10.0.0.206' (using password: YES)strong text*

You're using the wrong password. You need to use the password that you provided when you set up your MySQL server. Also, do not post passwords into forums. I would suggest changing that password immediately.