pymysql.err.OperationalError: (1045, "Access denied for user 'frappe'@'' (using password: NO)")

I configure multi bench on ubuntu 20.04 and every thing goes smooth when i execute the run command

docker run -e "MAINTENANCE_MODE=1" -v erpnext_sites-vol:/home/frappe/frappe-bench/sites --network webproxy frappe/erpnext-worker:version-12 migrate

i’m getting access denied error although i have setup root password for maria db server in .env file and haven’t setup frappe user for database upon running above ammand i’m getting following response

Migrating Traceback (most recent call last): File "/home/frappe/frappe-bench/commands/", line 51, in <module> main() File "/home/frappe/frappe-bench/commands/", line 44, in main migrate_sites() File "/home/frappe/frappe-bench/commands/", line 35, in migrate_sites migrate() File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 40, in migrate clear_global_cache() File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 54, in clear_global_cache clear_website_cache() File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 322, in clear_cache frappe.clear_cache("Guest") File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 588, in clear_cache frappe.cache_manager.clear_user_cache(user) File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 32, in clear_user_cache clear_notifications(user) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/", line 120, in clear_notifications config = get_notification_config() File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/", line 200, in get_notification_config return frappe.cache().hget("notification_config", user, _get) File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/", line 186, in hget value = generator() File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/", line 180, in _get hooks = frappe.get_hooks() File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 968, in get_hooks hooks = _dict(cache().get_value("app_hooks", load_app_hooks)) File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/", line 79, in get_value val = generator() File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 942, in load_app_hooks for app in [app_name] if app_name else get_installed_apps(sort=True): File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 906, in get_installed_apps installed = json.loads(db.get_global("installed_apps") or "[]") File "/home/frappe/frappe-bench/apps/frappe/frappe/database/", line 702, in get_global return self.get_default(key, user) File "/home/frappe/frappe-bench/apps/frappe/frappe/database/", line 706, in get_default d = self.get_defaults(key, parent) File "/home/frappe/frappe-bench/apps/frappe/frappe/database/", line 724, in get_defaults defaults = frappe.defaults.get_defaults(parent) File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 77, in get_defaults globald = get_defaults_for() File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 204, in get_defaults_for where parent = %s order by creation""", (parent,), as_dict=1) File "/home/frappe/frappe-bench/apps/frappe/frappe/database/", line 122, in sql self.connect() File "/home/frappe/frappe-bench/apps/frappe/frappe/database/", line 75, in connect self._conn = self.get_connection() File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/", line 90, in get_connection local_infile = frappe.conf.local_infile) File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/", line 94, in Connect return Connection(*args, **kwargs) File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/", line 325, in __init__ self.connect() File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/", line 599, in connect self._request_authentication() File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/", line 861, in _request_authentication auth_packet = self._read_packet() File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/", line 684, in _read_packet packet.check_error() File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/", line 220, in check_error err.raise_mysql_exception(self._data) File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/", line 109, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.OperationalError: (1045, "Access denied for user 'frappe'@'' (using password: NO)")

I don’t know why mysql denies access,

last test did migration successfully in docker Travis CI - Test and Deploy with Confidence

i’m facing that problem and i haven’t found any solution to resolve that i followed Multi bench please guide me to solution

For those experiencing a similar error in the future, one of the mistakes I had made was setting up ufw, but not allowing mariadb through it. The digitalocean guide walks you through setting up ufw, but you have to modify it to allow mariadb through it.

Having the same issue on a single bench local setup using docker-composer

erpnext-python_1          | pymysql.err.OperationalError: (1045, "Access denied for user '_c406468ad38db6c7'@'' (using password: YES)")
mariadb_1                 | 2021-01-16 19:40:50 31 [Warning] Access denied for user '_c406468ad38db6c7'@'' (using password: YES)
mariadb_1                 | 2021-01-16 19:41:50 32 [Warning] Access denied for user '_c406468ad38db6c7'@'' (using password: YES)
mariadb_1                 | 2021-01-16 19:42:50 33 [Warning] Access denied for user '_c406468ad38db6c7'@'' (using password: YES)

potential reason for the error.

  • erpnext container(s) with distinct IPs try to connect to mysql with credentials of database
  • mariadb user set in site_config.json or even mariadb root user (mysql.user) has Host column set to specific IP and not wildcard (%)
  • It happens on some machines. It never happens on Travis test runs travis-ci/job/472342255
  • If it happens, user which is trying to access needs host column set as %.
  • Solution option: Fixing mariadb issues after rebuilding the container