mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

816 views Asked by At

I'm trying to connect database for my login page, using Xampp server (myphpadmin)

The python code as follows:

run.py

from application import app

if __name__=="__main__":
    app.run(host ='0.0.0.0', debug=True)

init.py

from flask import Flask 

app=Flask(__name__)

from application import main

main.py

from application import app
from flask import Flask,render_template,request
import mysql.connector


@app.route('/')
def login():
    return render_template('login.html')

@app.route('/result',methods=['POST','GET'])
def result():
    mydb=mysql.connector.connect(
        host="localhost",
        user="root",
        password="",
        database="user-system"
    )
    mycursor=mydb.cursor()
    if request.method=='POST':
        signup=request.form
        username=signup['user']
        password=signup['pass']
        mycursor.execute("select *form user where name=='"+username+"' and password=='"+password+"'")
        r=mycursor.fetchall()
        count=mycursor.rowcount
        if count==1:
            return render_template("test.html")
        elif count> 1:
            return "More than One USER "
        else:
            return render_template("login.html")
    mydb.commit()
    mycursor.close()

The code is running successfully but after login using the database data it redirects me to the following error is :

Image shows the Error:

1

There are 1 answers

0
Jordy On

You're using user root with no password maybe not be allowed. My Suggest is to add new user account with a password to access your MySQL database correctly with this steps:

  1. Open phpMyAdmin.
  2. Click User accounts
  3. Click Add user account
  4. Put your new username and fill the password, then check all on Global Privileges and click Go
  5. Finally, edit this lines:
mydb=mysql.connector.connect(
        host="localhost",
        user="<your new username>",
        password="<your new password>",
        database="user-system"
    )