Access denied there mariadb database on linux python3

Asked

Viewed 65 times

0

good afternoon, I was doing some tests and I decided to try using python3 to manipulate databases but I can never connect with the database with python because the same error always happens:

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

I did the complete installation of mariadb with the command

sudo_mysql_secure_installation

I don’t know if I need any more commands or do anything else.

The code I used to connect to python3 is as follows:

import mysql.connector
mydb=mysql.connector.connect(host="localhost",database="testes",user="root",passwd="hugo")
print(mydb)
  • Make sure that the password is correct and that the basis "tests" actually exists (I don’t know if this would cause a denied access, but it’s good to check).

  • yes there is such a database

  • This has nothing to do with Python, the error is that you did not authorize a "root" user with "Ugo" password to access the DB by the "localhost" path. You need to check and fix this directly with the DB tools, test access with these tools, making sure it works, then use it in Python.

1 answer

-1


"print(mydb)" Here you are trying to print the object so the error tries that way it should work.

import mysql.connector

(mydb = mysql.connector.connect(
    host="localhost",
    database="testes",
    user="root",
    passwd="hugo"
    )

#Cria Um objeto Cursor
cursor = (mydb.cursor()
#execulta o comando mysql
cursor.execute('Select * from tabela')
#recebe o valor da consulta
myresult = cursor.fetchall()
for resultado in myresult:
    print (resultado[1],"-->", resultado[2]) # imprime o resultado

Browser other questions tagged

You are not signed in. Login or sign up in order to post.