I am new to MySQL , i am trying to make a simple registration form using MySQL database and python with FLask as severside framework .
I got the following error when running code in localhost :

MySQL configuration :
app.config['MySQL_HOST'] ='localhost'
app.config['MySQL_USER'] = 'blacksmith'
app.config['MySQL_PASSWORD'] = '123456'
app.config['MySQL_DB'] = 'myflaskapp'
app.config['MySQL_CURSORCLASS'] = 'DictCursor'
register function with route
@app.route('/register',methods=['GET','POST']) #route accepts get request per default but we precise here post also
def register():
form = RegisterForm(request.form)
if request.method == 'POST' and form.validate(): # check if form is validated and its a post request
name = form.name.data
email = form.email.data
username= form.username.data
password = sha256_crypt.encrypt(str(form.password.data))
#create cursor
cur =mysql.connection.cursor()
# execute SQL command
cur.execute("INSERT INTO users(name,email,username,password) VALUES (%s,%s,%s,%s)",(name,email,username,password) )
#commit to DB
mysql.connection.commit()
#close connection
cur.close()
return render_template('register.htm',form=form)
I got the same error ( Access denied for user root@localhost ) also when i access MySQL shell in my bash shell using the command
mysql -u root
( i had to use sudo command to access the database )
The problem that i didn't set any password for MySQL database access , and the same error persists even when trying to change it with another password using the command :
ALTER USER 'user'@'hostname' IDENTIFIED BY 'newPass';
I tried also to change password in MySQL configuration with no success .
I am stuck with that any help please !