title: MySQL error : Access denied for user (using password:NO) - python
body: <p>I am new to MySQL , i am trying to make a simple registration form using MySQL database and python with FLask as severside framework .</p>
  
  <p>I got the following error when running code in localhost :
  <a href="https://i.stack.imgur.com/JhYvU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JhYvU.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>MySQL configuration :</p>
  </blockquote>
  
  <pre><code>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'
  </code></pre>
  
  <blockquote>
    <p>register function with route</p>
  </blockquote>
  
  <pre><code>@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)
  </code></pre>
  
  <p>I got the same error ( <strong>Access denied for user root@localhost</strong> ) also when i access MySQL shell in my bash shell using the command </p>
  
  <pre><code>mysql -u root
  </code></pre>
  
  <p>( i had to use <strong>sudo command</strong> to access the database )</p>
  
  <p>The problem that i didn't set <strong>any password</strong> for MySQL database access , and the same error persists even when trying to change it with another password using the command :</p>
  
  <pre><code>ALTER USER 'user'@'hostname' IDENTIFIED BY 'newPass';
  </code></pre>
  
  <p>I tried also to change password in MySQL configuration with no success .</p>
  
  <p><strong>I am stuck with that any help please !</strong></p>