0

So when I run this python script on my Ubuntu 20.04 machine:

import mysql.connector
cnx = mysql.connector.connect(user='root', password = '',
                              host='127.0.0.1',
                              database='test')
cnx.close()

it gives me the following error : mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'test'@'localhost' (using password: NO) Any ideas ?

user13930404
  • 11
  • 1
  • 3
  • Obviously the connection states user: `test` where you show config with user: `root` , so somewhere there's something configured wrong. – Ron Sep 10 '20 at 12:16
  • Did you do any research, or red the DOCs ? [this answer](https://stackoverflow.com/questions/372885/how-do-i-connect-to-a-mysql-database-in-python?rq=1) can help – Ron Sep 10 '20 at 12:19

2 Answers2

0

check your user details using mysql.user table. You probably have an anonymous user ''@'localhost' or ''@'127.0.0.1'. so drop this user/create again or create new user.

0

I fixed my problem(sort of) by uninstalling mysql server and installing mariadb instead. although this is probably just avoiding the problem and not fixing it. It worked for me.

Hamid Naghipour
  • 3,465
  • 2
  • 26
  • 55
user13930404
  • 11
  • 1
  • 3