pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)") [MAC]

Facing this issue when I create a new site in frappe.
asking MySQL root password. I tried “frappe”, “admin”, “root”, blank
tried re-installing xamp.
still facing the issue
kindly help.

Thanks

============================== TERMINAL OUTPUT =======================
apples-MacBook-Air-26:frappe-bench parth$ bench new-site meeting.dev
MySQL root password:
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py”, line 193, in _run_module_as_main
main”, mod_spec)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/Users/parth/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/Users/parth/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/Users/parth/frappe-bench/apps/frappe/frappe/commands/site.py”, line 32, in new_site
db_type=db_type)
File “/Users/parth/frappe-bench/apps/frappe/frappe/commands/site.py”, line 69, in _new_site
source_sql=source_sql, force=force, reinstall=reinstall, db_type=db_type)
File “/Users/parth/frappe-bench/apps/frappe/frappe/installer.py”, line 34, in install_db
setup_database(force, source_sql, verbose)
File “/Users/parth/frappe-bench/apps/frappe/frappe/database/init.py”, line 16, in setup_database
return frappe.database.mariadb.setup_db.setup_database(force, source_sql, verbose)
File “/Users/parth/frappe-bench/apps/frappe/frappe/database/mariadb/setup_db.py”, line 39, in setup_database
if force or (db_name not in dbman.get_database_list()):
File “/Users/parth/frappe-bench/apps/frappe/frappe/database/db_manager.py”, line 61, in get_database_list
return [d[0] for d in self.db.sql(“SHOW DATABASES”)]
File “/Users/parth/frappe-bench/apps/frappe/frappe/database/database.py”, line 122, in sql
self.connect()
File “/Users/parth/frappe-bench/apps/frappe/frappe/database/database.py”, line 75, in connect
self._conn = self.get_connection()
File “/Users/parth/frappe-bench/apps/frappe/frappe/database/mariadb/database.py”, line 90, in get_connection
local_infile = frappe.conf.local_infile)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/init.py”, line 94, in Connect
return Connection(*args, **kwargs)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 325, in init
self.connect()
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 599, in connect
self._request_authentication()
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 882, in _request_authentication
auth_packet = _auth.caching_sha2_password_auth(self, auth_packet)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/_auth.py”, line 265, in caching_sha2_password_auth
pkt = _roundtrip(conn, data)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/_auth.py”, line 122, in _roundtrip
pkt = conn._read_packet()
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 684, in _read_packet
packet.check_error()
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/Users/parth/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, “Access denied for user ‘root’@‘localhost’ (using password: YES)”)

Refer to mysql - Access Denied for User 'root'@'localhost' (using password: YES) - No Privileges? - Stack Overflow

One of the solutions from the linked question usually works.

      #IF... this happens....
      #ERROR 1045 (28000): Access denied for user '8de49ae55a02e7ac'@'localhost' (using password: YES)
      DBname=$(cat ~/frappe-bench/sites/site1.local/site_config.json | awk '/db_name/ {print $2}' | sed "s/\"//g" | sed "s/,//g")
      DBpass=$(cat ~/frappe-bench/sites/site1.local/site_config.json | awk '/db_password/ {print $2}' | sed "s/\"//g")
      #
      mysql -uroot -p$MySQLpwd -Bse "GRANT ALL PRIVILEGES ON *.* TO '$DBname'@'localhost' IDENTIFIED BY '$DBpass' WITH GRANT OPTION;"
      mysql -uroot -p$MySQLpwd -Bse "GRANT ALL PRIVILEGES ON *.* TO '$DBname'@'127.0.0.1' IDENTIFIED BY '$DBpass' WITH GRANT OPTION;"
      #
      mysql -uroot -p$MySQLpwd -Bse "set password for '$DBname'@'localhost' = password('$DBpass');"
      mysql -uroot -p$MySQLpwd -Bse "set password for '$DBname'@'127.0.0.1' = password('$DBpass');"
      #delete the DB and re-run
      bench new-site site1.local
1 Like

Check if skip_name_resolve is set in your mysql config. It was the culprit in our case.

I know it’s been a time but for my case the solution was to just changing the password by running the following command.

sudo mysql_secure_installation

then, for current password: press enter if you were not set, but if you did, just type the one you used during the installation.

And for the new Password : type your new Password that you will be using from now on wards eve when creating bench site.
That’s it.

1 Like

Run these below commands and then create site

GRANT ALL PRIVILEGES ON . TO ‘root’@‘%’ IDENTIFIED BY ‘your_password’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO ‘root’@‘localhost’ IDENTIFIED BY ‘your_password’ WITH GRANT OPTION;

it solved the same issue at our end.

1 Like