Question

"Access denied for user 'root'@'localhost'" during pymysql.connections

I tried to set up a LAMP server by following this article. It was set up without errors and I can “ssh root@localhost” with my password. But when I was ready to test it by going to http://my_server_ip using Firefox, it gave me a sequence of function calls leading up to the error: In /var/www/test/index.py 15 user=‘root’, 16 passwd=‘my_passwd’, => 17 host=‘localhost’) 18 c = conn.cursor() 19 host undefined In in Connect(*args=(), **kwargs={‘db’: ‘example’, ‘host’: ‘localhost’, ‘passwd’: ‘my_passwd’, ‘user’: ‘root’}) 88 “”" 89 from .connections import Connection => 90 return Connection(*args, **kwargs) 91 92 from . import connections as _orig_conn Connection = <class ‘pymysql.connections.Connection’>, args = (), kwargs = {‘db’: ‘example’, ‘host’: ‘localhost’, ‘passwd’: ‘my_passwd’, ‘user’: ‘root’} … 697 self._sock = None 698 else: => 699 self.connect() 700 701 def _create_ssl_ctx(self, sslp): self = <pymysql.connections.Connection object>, self.connect = <bound method Connection.connect of <pymysql.connections.Connection object>> … errorclass = <class ‘pymysql.err.InternalError’>, errno = 1698, errval = “Access denied for user ‘root’@‘localhost’”

InternalError: (1698, “Access denied for user ‘root’@‘localhost’”)

Can you please help me with this?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

After some research, it is solved by making a couple of changes.

  1. For errno 1698, see link: mysql> update user set plugin=“mysql_native_password” where user=‘root’;

  2. For errno 1045, see link: mysql> update user set authentication_string=password(“myPasswd#”) where user=‘root’;

  3. For ERROR 1819 (HY000): Your password does not satisfy the current policy requirements, see link for the password rule and how to change it.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.