最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - mariadb.OperationalError: Access denied for user... but credentials are correct - Stack Overflow

programmeradmin0浏览0评论

I use this simple connection script:

import configparser
import mariadb

config = configparser.ConfigParser()
config.read('dbconfig.ini')
config_default = config['DEFAULT']

print(f' mariadb -h {config_default["server"]} -u {config_default["username"]} -p{config_default["password"]} -P {config_default["port"]} {config_default["database"]}')

conn = mariadb.connect(
    user=config_default['username'],
    password=config_default['password'],
    host=config_default['server'],
    port=int(config_default['port']),
    database=config_default['database']
)

When I run this, I get:

mariadb.OperationalError: Access denied for user 'myuser'@'myhost.local' (using password: YES)

But when I just call the output of the print statement, it connects just fine. So i guess the credentials and everything is correct. For testing I also chose a password without any special characters.

My setup:

  • Database: 11.4.4-MariaDB-log
  • Python: Python 3.13.1
  • Connector: mariadb==1.1.11
  • Database client: Ver 15.1 Distrib 10.11.6-MariaDB

I use this simple connection script:

import configparser
import mariadb

config = configparser.ConfigParser()
config.read('dbconfig.ini')
config_default = config['DEFAULT']

print(f' mariadb -h {config_default["server"]} -u {config_default["username"]} -p{config_default["password"]} -P {config_default["port"]} {config_default["database"]}')

conn = mariadb.connect(
    user=config_default['username'],
    password=config_default['password'],
    host=config_default['server'],
    port=int(config_default['port']),
    database=config_default['database']
)

When I run this, I get:

mariadb.OperationalError: Access denied for user 'myuser'@'myhost.local' (using password: YES)

But when I just call the output of the print statement, it connects just fine. So i guess the credentials and everything is correct. For testing I also chose a password without any special characters.

My setup:

  • Database: 11.4.4-MariaDB-log
  • Python: Python 3.13.1
  • Connector: mariadb==1.1.11
  • Database client: Ver 15.1 Distrib 10.11.6-MariaDB
Share Improve this question asked Feb 1 at 23:15 Mr. ClearMr. Clear 6526 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It was clear that there is some embarrassing reason for this: I used parenthesis for the password in the config file. Python added them to the password, so the password was wrong. When testing on the shell, the shell removed the parenthesis, so the password was correct.

发布评论

评论列表(0)

  1. 暂无评论