Answer the question
In order to leave comments, you need to log in
How to connect to mariadb from pymysql?
For some reason, when trying to run the script, an error occurs (1045, "Access denied for user 'bot'@'my_local_ip' (using password: YES)"), although the login password is correct. the settings on the server also seem to be correct, please help me figure it out...
Here is the script:
from config import host, db_user, password, db_name
import pymysql
def database():
try:
connection = pymysql.connect(
host=host,
port=3306,
user = bot,
password=password,
database= test_db,
cursorclass=pymysql.cursors.DictCursor
)
print('successfully connected to coinsniper DB!')
try:
with connection.cursor() as cursor:
select_all_rows = "SELECT * FROM users"
cursor.execute(select_all_rows)
rows = cursor.fetchall()
for row in rows:
print(row)
finally:
connection.close()
except Exception as ex :
print('Connection refused...')
print(ex)
database()
mariadb database and remote user configuration:
DB - 'test_db'
username 'bot':
GRANT USAGE ON *.* TO `bot`@`%` IDENTIFIED BY PASSWORD '*A2D561F8621B6'
GRANT ALL PRIVILEGES ON `test_db `.* TO `bot`@`%` WITH GRANT OPTION
ip in /etc/mysql/mariadb.conf.d/50-server.cnf bind-address
parameter fixed to = 0.0.0.0
Software Version:
10.5.11-MariaDB-1
Debian GNU/Linux 11 (bullseye)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question