Fresh install ends with error "Access denied for user 'root' @ 'localhost'"

To install ERPNext (in test environment) I tried to follow both the official guides and the many guides on the net.
I always arrive at the same point and I always get the same DB access error.
With mysql_secure_installation I assign to root the password “Root-Passw0rd”
Later in MariaDB:
CREATE USER erpnext@localhost IDENTIFIED BY 'Erp-N3xt';

When I then run:
bench new-site erp.mydomain.tld
I get the error “Access denied for user ‘root’ @ ‘localhost’”
Whether you use password Root-Passw0rd or password Erp-N3xt.

So, can’t configure database access parameters in a file? Which? How?

This is the last output:

bench new-site erp.mydomain.tld
WARN: bench is installed in editable mode!

This is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`

MySQL root password:
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/srv/bench/erpnext/apps/frappe/frappe/utils/bench_helper.py", line 99, in <module>
    main()
  File "/srv/bench/erpnext/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/srv/bench/erpnext/apps/frappe/frappe/commands/site.py", line 40, in new_site
    db_port=db_port, new_site=True)
  File "/srv/bench/erpnext/apps/frappe/frappe/installer.py", line 72, in _new_site
    no_mariadb_socket=no_mariadb_socket,
  File "/srv/bench/erpnext/apps/frappe/frappe/installer.py", line 106, in install_db
    setup_database(force, source_sql, verbose, no_mariadb_socket)
  File "/srv/bench/erpnext/apps/frappe/frappe/database/__init__.py", line 16, in setup_database
    return frappe.database.mariadb.setup_db.setup_database(force, source_sql, verbose, no_mariadb_socket=no_mariadb_socket)
  File "/srv/bench/erpnext/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 "/srv/bench/erpnext/apps/frappe/frappe/database/db_manager.py", line 60, in get_database_list
    return [d[0] for d in self.db.sql("SHOW DATABASES")]
  File "/srv/bench/erpnext/apps/frappe/frappe/database/database.py", line 122, in sql
    self.connect()
  File "/srv/bench/erpnext/apps/frappe/frappe/database/database.py", line 75, in connect
    self._conn = self.get_connection()
  File "/srv/bench/erpnext/apps/frappe/frappe/database/mariadb/database.py", line 91, in get_connection
    local_infile = frappe.conf.local_infile)
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/pymysql/connections.py", line 325, in __init__
    self.connect()
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/pymysql/connections.py", line 599, in connect
    self._request_authentication()
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/pymysql/connections.py", line 861, in _request_authentication
    auth_packet = self._read_packet()
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/srv/bench/erpnext/env/lib/python3.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.InternalError: (1698, "Access denied for user 'root'@'localhost'")

I also followed this guide
https://github.com/frappe/frappe/wiki/The-Hitchhiker%27s-Guide-to-Installing-Frappe-on-Linux

in which I only find traces of the MariaDB Root password, yet there is still the error:
pymysql.err.InternalError: (1698, “Access denied for user ‘root’@‘localhost’”)

In my opinion, the command bench new-site cannot connect to MariaDB.

Solved with this command:
sudo mysql -uroot -pPASSWORD -Bse "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;"

7 Likes