Here is how I sorted the error
pymysql.err.OperationalError: (1698, “Access denied for user ‘root’@‘localhost’”)
while creating the site by running command
bench new-site site1.local
I also faced following error. Following is my full terminal message trail.
frappe@erpnext14-ubuntu22041:~/frappe-bench$ bench new-site site1.local
MySQL root password:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
main()
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
click.Group(commands=commands)(prog_name="bench")
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 74, in new_site
_new_site(
File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 80, in _new_site
install_db(
File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 156, in install_db
setup_database(force, source_sql, verbose, no_mariadb_socket)
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/__init__.py", line 20, in setup_database
return frappe.database.mariadb.setup_db.setup_database(
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 41, in setup_database
if force or (db_name not in dbman.get_database_list()):
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/db_manager.py", line 49, in get_database_list
return self.db.sql("SHOW DATABASES", pluck=True)
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 199, in sql
self.connect()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 113, in connect
self._conn = self.get_connection()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 98, in get_connection
conn = self._get_connection()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 104, in _get_connection
return self.create_connection()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 107, in create_connection
return pymysql.connect(**self.get_connection_settings())
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 353, in __init__
self.connect()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 633, in connect
self._request_authentication()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 907, in _request_authentication
auth_packet = self._read_packet()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 725, in _read_packet
packet.raise_for_error()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
When I tried to uninstall the site with command bench drop-site site1.local , I again got the error as below:
Taking backup of site1.local
================================================================================
Error: The operation has stopped because backup of site1.local's database failed.
Reason: (1045, "Access denied for user '_c6a99b789ee42f7a'@'localhost' (using password: YES)")
Fix the issue and try again.
Hint: Use 'bench drop-site site1.local --force' to force the removal of site1.local
frappe@erpnext14-ubuntu22041:~/frappe-bench$ bench drop-site site1.local --force
Taking backup of site1.local
Dropping site database and user
MySQL root password:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
main()
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
click.Group(commands=commands)(prog_name="bench")
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 832, in drop_site
_drop_site(site, db_root_username, db_root_password, archived_sites_path, force, no_backup)
File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 870, in _drop_site
drop_user_and_database(frappe.conf.db_name, db_root_username, db_root_password)
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/__init__.py", line 37, in drop_user_and_database
return frappe.database.mariadb.setup_db.drop_user_and_database(
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 86, in drop_user_and_database
dbman.drop_database(db_name)
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/db_manager.py", line 30, in drop_database
self.db.sql_ddl(f"DROP DATABASE IF EXISTS `{target}`")
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 363, in sql_ddl
self.commit()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 999, in commit
self.sql("commit")
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 199, in sql
self.connect()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 113, in connect
self._conn = self.get_connection()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 98, in get_connection
conn = self._get_connection()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 104, in _get_connection
return self.create_connection()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 107, in create_connection
return pymysql.connect(**self.get_connection_settings())
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 353, in __init__
self.connect()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 633, in connect
self._request_authentication()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 907, in _request_authentication
auth_packet = self._read_packet()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 725, in _read_packet
packet.raise_for_error()
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
Even using –force didn’t help. Then I referred the official documentation and used following command to create site and it successfully created site. But note that before running command, I manually deleted the site folder /home/frappe/frappe-bench/sites/site1.local
bench new-site site1.local --db-name erpnext --db-password password --db-root-username frappe --db-root-password password --admin-password password
I actually used the userid and password that i created while installing mariadb. my mariadb server admin user was frappe and password is password. This is apart from the root user that gets automatically created while installing mariadb.
And following is the message trail in my terminal:
frappe@erpnext14-ubuntu22041:~/frappe-bench$ bench new-site site1.local --db-name erpnext --db-password password --db-root-username frappe --db-root-password password --admin-password password
Installing frappe...
Updating DocTypes for frappe : [====================] 100%
Updating country info : [====================] 100%
Updating Dashboard for frappe
site1.local: SystemSettings.enable_scheduler is UNSET
*** Scheduler is disabled ***
frappe@erpnext14-ubuntu22041:~/frappe-bench$
It worked just like that!
For those who are interested in creating an explicit user for frappe in mariadb, here is what I did.
When the command sudo mysql_secure_installation is run, terminal shows some options to configure, here is what i chose to do:
-> Configuring MariaDB
Commands:
> sudo mysql_secure_installation
Result:
=> Enter current password for root (enter for none): Since you have not set one up yet, press ENTER to indicate “none”. I pressed **Enter**
=> Switch to unix_socket authentication [Y/n]: n (Since you already have a protected root account, you can skip this step. Type n and then press ENTER.)
=> Change the root password? [Y/n]:n (Type n and then press ENTER.)
=> Remove anonymous users? [Y/n]:y
=> Disallow root login remotely? [Y/n]: y
=> Remove test database and access to it? [Y/n]: y
=> Reload privilege tables now? [Y/n]: y
Message:
All done! If you've completed all of the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB!
Then, I did as follows:
-> Creating an Administrative User that Employs Password Authentication
Commands:
> sudo mariadb
> GRANT ALL ON *.* TO 'frappe'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
> FLUSH PRIVILEGES;
> exit