0

I connect mysql with pymysql. but below error raise

pymysql.connect(host='localhost', user='root', password="pass", db='db_name', charset='utf8', port=3306)

pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

So I check my root password. But Through "mysql -u root -p" I login in mysql. and I execute "grant all privileges on [db_name] to root@localhost;". but it's same. Also i execute "grant all privileges on [db_name] to root@localhost identified by "Password". but error raise "

error : "ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'password'' at line 1

Prabhakar
  • 1,138
  • 2
  • 14
  • 30
dnjs7292
  • 39
  • 1
  • 5
  • if you've set root password to Password (`.. identified by "Password"`), then pass this one as connection parameter for password. i mean, `pymysql.connect(host=..., user=.., password='Password', ...)` – marmeladze May 11 '18 at 16:43
  • sorry. i set same password. it's typo – dnjs7292 May 11 '18 at 17:04
  • It should be: "grant all privileges on [db_name] to 'root'@'localhost';" Note the quotes around root and localhost. Are you connecting to a remote database ? – Rambarun Komaljeet May 11 '18 at 17:17

1 Answers1

0

What version of MySQL are you using? I was not able to use PyMySQL with MySQL 8, so I had to downgrade to 5.4.

EDIT: Here's my thread on troubleshooting and ultimately resolving: PyMySQL Access Denied "using password (no") but using password

paulmiller3000
  • 436
  • 8
  • 24