0

I make a telegram bot using python and MySQL. I can enter the database in terminal, but when I run my python code, it says I have no permission.

      ilyacherne@vh289 ~ $ python3 /home/i/ilyacherne/public_html/cgi-bin/bot.py
Traceback (most recent call last):
  File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 239, in _open_connection
    self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Access denied for user 'ilyacherne'@'77.222.61.25' (using password: YES)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/i/ilyacherne/public_html/cgi-bin/bot.py", line 3, in <module>
    import config
  File "/home/i/ilyacherne/public_html/cgi-bin/config.py", line 8, in <module>
    database = mysql.connect(
  File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/__init__.py", line 272, in connect
    return CMySQLConnection(*args, **kwargs)
  File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 85, in __init__
    self.connect(**kwargs)
  File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 1009, in connect
    self._open_connection()
  File "/home/i/ilyacherne/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 241, in _open_connection
    raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'ilyacherne'@'77.222.61.25' (using password: YES)

I checked the password, host name, database name and user. I connect with this code:

database = mysql.connect(
    host = '77.222.61.25',
    user = 'ilyacherne',
    passwd = 'CENSORED',
    database = 'ilyacherne'
)

support said that MySql 5.7 connects to socket by default and i connect just with 'sudo mysql', and then they reccomended me try this:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Current-Root-Password'; FLUSH PRIVILEGES;

but it says:

ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
ERROR 1227 (42000): Access denied; you need (at least one of) the RELOAD privilege(s) for this operation
ilya
  • 1
  • 2
  • Is the username allowed to access MySQL *remotely*, or only locally? – S3DEV Oct 04 '21 at 20:58
  • Possible duplicate of [MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)](https://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw) – S3DEV Oct 04 '21 at 21:21

1 Answers1

0
  Pip install mysql-connector-python

Then import mysql-connector.

CCCC
  • 241
  • 2
  • 10
  • Please explain in what way this answers the question. I’m struggling to see it myself. Simply installing and importing mysql-connector is not at all likely to solve the issue. Aside, `pip` is lower case. – S3DEV Oct 04 '21 at 20:59
  • https://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw kindly check out the contents of that link. Although when I had a similar issue, the mysql-connector-python helped me – CCCC Oct 04 '21 at 21:12
  • 1) The answers on the linked question refer to user creation and permissions. 2) Simply installing and importing mysql-connector is not going to fix this issue; there is more to it. – S3DEV Oct 04 '21 at 21:16
  • Okay. Mysql-connector-python is different from mysql-connector. What I do? If a suggestion wouldn't cause any disruption, I give it a trial. – CCCC Oct 05 '21 at 05:53