Error while creating bench new-site (1045, "Access denied for user 'root'@'localhost'

on running bench new-site library.test it asks for MySQL root password, dining installation of mariadb no password was set, on entering without password it raise this error bellow is the complete log.

MySQL root password: 
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/commands/site.py", line 76, in new_site
    _new_site(
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/installer.py", line 80, in _new_site
    install_db(
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/installer.py", line 155, in install_db
    setup_database(force, source_sql, verbose, no_mariadb_socket)
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/__init__.py", line 20, in setup_database
    return frappe.database.mariadb.setup_db.setup_database(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 36, in setup_database
    if force or (db_name not in dbman.get_database_list()):
                                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/db_manager.py", line 49, in get_database_list
    return self.db.sql("SHOW DATABASES", pluck=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/database.py", line 210, in sql
    self.connect()
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/database.py", line 125, in connect
    self._conn = self.get_connection()
                 ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 102, in get_connection
    conn = self._get_connection()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 108, in _get_connection
    return self.create_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 111, in create_connection
    return pymysql.connect(**self.get_connection_settings())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py", line 352, in __init__
    self.connect()
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py", line 636, in connect
    self._request_authentication()
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py", line 911, in _request_authentication
    auth_packet = self._read_packet()
                  ^^^^^^^^^^^^^^^^^^^
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/pymysql/connections.py", line 729, in _read_packet
    packet.raise_for_error()
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/Users/naruto/Desktop/cogentlabs/frappe-bench/env/lib/python3.11/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")```

The error message OperationalError pymysql.err.OperationalError: (1045, “Access denied for user (…) (using password: YES)”) indicates that you are trying to connect to a MySQL database with an incorrect username or password. The 1045 error code specifically means that the database server denied your request because the username and password combination you provided did not match a valid user account.

I didn’t set username, password during MariaDB installtion which have installed MySQL. I also did not provide username password during site creation

I think you did the installation wrong, follow this guide that helped me a lot.

1 Like

I am on macOS not on ubuntu

You Can Run these command step by step-
-sudo mysql -u root -p

  • ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123’; (instead of 123 you can set new password)
    -sudo mysql service restart

You can be guided by the following tutorial.