0

I set up a MySQL database on Ubuntu 18.04, and am trying to connect via python using mysql.connector. The database is on the same computer as the instance of python (Acer predator).

Connecting to the MySQL database through the terminal works. But using mysql.connector in python 3.6 keeps producing the following error:

mysql.connector.errors.ProgrammingError: 1698 (28000): Access denied for user 'root'@'localhost'

I keep seeing troubleshooting tips talking about auth_socket or granting privileges even here in Stack Overflow, but these are all focused on connecting with MySQL, whereas my issue is specific to mysql.connector in python.

Code I am using is below, and I've tried it with other users, no password included, and even no host included - but nothing works.

import mysql.connector
conn = mysql.connector.connect(host='localhost',
       database='exampledatabase',
       user='root',
       password='examplepassword')
Vickel
  • 7,879
  • 6
  • 35
  • 56
Daniel Moisio
  • 59
  • 1
  • 11
  • P.s. the python instance I am using is just the standard shell produced with 'idle' in the terminal – Daniel Moisio Dec 25 '18 at 20:15
  • Check you connection parameters again else it is issue with MySQL server issue – Code Kadiya Dec 25 '18 at 20:19
  • So connecting to the server with those credentials works for a node server or some other instance? How did you rule out the SQL server itself being the problem? – Jon Reinhold Dec 25 '18 at 21:02
  • I have no reason to believe SQL is the issue ... could be but I connect to mysql from the terminal. "sudo mysql -u root" brings up mysql in the terminal, and I can work with the database from there – Daniel Moisio Dec 25 '18 at 21:22
  • Try to access without password. Because you used `mysql -u root` – KC. Dec 26 '18 at 08:53
  • Kcorlidy - per my initial question, I have tried without password and any number of other connect() combinations. Nothing works, it seems the problem is elsewhere. – Daniel Moisio Dec 26 '18 at 23:07
  • Be advised, after much banging my head the 2nd answer down listed here: https://stackoverflow.com/questions/7864276/cannot-connect-to-database-server-mysql-workbench ended up doing the trick. – Daniel Moisio Dec 29 '18 at 20:40
  • Was as simple as altering the password associated with the root user I guess. Phew!! – Daniel Moisio Dec 29 '18 at 20:41

0 Answers0