Description:
So i have in MySQL 'tst'@'localhost' user:
[root@centos-base ~]# mysql -u tst -p --host='localhost'
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 5.5.44-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> \q
[root@centos-base ~]# mysql -u tst -p --host='127.0.0.1'
Enter password:
ERROR 1045 (28000): Access denied for user 'tst'@'127.0.0.1' (using password: YES)
When i used it in a script:
import mysql.connector
from mysql.connector import errorcode
def check_mysql_flush_log_user():
# Creating test Database and user for flushing binary logs.
# Connection Settings
config = {
'user': 'tst',
'password': '12345',
'host': 'localhost',
# 'database': 'mysql',
'raise_on_warnings': True,
}
# Open connection
try:
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
query1 = "create database if not exists bck"
print("Creating Test User (test_backup)+-+-+-+-+-+-+-+-+-++-+-+-+-+-OK")
time.sleep(2)
print("Creating Test Database (bck)+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-OK")
cursor.execute(query1)
cursor.close()
cnx.close()
return True
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
#print("Something is wrong with your user name or password!!!")
print(err)
return False
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exists")
return False
elif err.errno == errorcode.ER_DB_CREATE_EXISTS:
print("Database Already exists")
return True
else:
print(err)
return False
check_mysql_flush_log_user()
[root@centos-base ~]# /opt/Python-3.3.2/bin/python3 test_connection.py
1045 (28000): Access denied for user 'tst'@'127.0.0.1' (using password: YES)
It is using '127.0.0.1' even if explicitly specifying 'localhost'.
How to repeat:
1. create user 'tst'@'localhost' identified by '12345';
grant all on *.* to 'tst'@'localhost';
2. Try to connect to MySQL using Python code above. using 'host':'localhost'
Suggested fix:
Workaround is creating same user with '127.0.0.1'.
Description: So i have in MySQL 'tst'@'localhost' user: [root@centos-base ~]# mysql -u tst -p --host='localhost' Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 49 Server version: 5.5.44-MariaDB-log MariaDB Server Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> \q [root@centos-base ~]# mysql -u tst -p --host='127.0.0.1' Enter password: ERROR 1045 (28000): Access denied for user 'tst'@'127.0.0.1' (using password: YES) When i used it in a script: import mysql.connector from mysql.connector import errorcode def check_mysql_flush_log_user(): # Creating test Database and user for flushing binary logs. # Connection Settings config = { 'user': 'tst', 'password': '12345', 'host': 'localhost', # 'database': 'mysql', 'raise_on_warnings': True, } # Open connection try: cnx = mysql.connector.connect(**config) cursor = cnx.cursor() query1 = "create database if not exists bck" print("Creating Test User (test_backup)+-+-+-+-+-+-+-+-+-++-+-+-+-+-OK") time.sleep(2) print("Creating Test Database (bck)+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-OK") cursor.execute(query1) cursor.close() cnx.close() return True except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: #print("Something is wrong with your user name or password!!!") print(err) return False elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exists") return False elif err.errno == errorcode.ER_DB_CREATE_EXISTS: print("Database Already exists") return True else: print(err) return False check_mysql_flush_log_user() [root@centos-base ~]# /opt/Python-3.3.2/bin/python3 test_connection.py 1045 (28000): Access denied for user 'tst'@'127.0.0.1' (using password: YES) It is using '127.0.0.1' even if explicitly specifying 'localhost'. How to repeat: 1. create user 'tst'@'localhost' identified by '12345'; grant all on *.* to 'tst'@'localhost'; 2. Try to connect to MySQL using Python code above. using 'host':'localhost' Suggested fix: Workaround is creating same user with '127.0.0.1'.