question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Description of the issue

My issue is similar to this one, although on production (that issue is over a year old, didn’t want to necro open it, and it was noted to open new issue for production; also, not using bench, as this is production so, not all is relevant; although I did try some of the solutions there, without success ): https://github.com/frappe/frappe_docker/issues/239

Context information (for bug reports)

Steps to reproduce the issue

  1. After what appeared to be a successful setup of Docker et al, following the Docker installation instructions
  2. Get to the point of starting things up by running the following command:
docker exec -it \                          
    -e "SITE_NAME=$SITE_NAME" \
    -e "DB_ROOT_USER=$DB_ROOT_USER" \
    -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \
    -e "ADMIN_PASSWORD=$ADMIN_PASSWORD" \
    -e "INSTALL_APPS=erpnext" \
    mysitecom_erpnext-python_1 docker-entrypoint.sh new

Observed result

Access denied for user roor error: pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'172.19.0.6' (using password: YES)")

Expected result

Expected root to have access to mariadb

Stacktrace / full error message if available

docker exec -it \                          
    -e "SITE_NAME=$SITE_NAME" \
    -e "DB_ROOT_USER=$DB_ROOT_USER" \
    -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \
    -e "ADMIN_PASSWORD=$ADMIN_PASSWORD" \
    -e "INSTALL_APPS=erpnext" \
    mysitecom_erpnext-python_1 docker-entrypoint.sh new

Attempt 1 to connect to mariadb:3306
Attempt 1 to connect to redis-queue:6379
Attempt 1 to connect to redis-cache:6379
Attempt 1 to connect to redis-socketio:6379
Connections OK

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/commands/new.py", line 118, in <module>
    main()
  File "/home/frappe/frappe-bench/commands/new.py", line 70, in main
    db_port=db_port,
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 72, in _new_site
    no_mariadb_socket=no_mariadb_socket,
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 106, in install_db
    setup_database(force, source_sql, verbose, no_mariadb_socket)
  File "/home/frappe/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, no_mariadb_socket=no_mariadb_socket)
  File "/home/frappe/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 "/home/frappe/frappe-bench/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 "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 121, in sql
    self.connect()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 74, in connect
    self._conn = self.get_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 90, in get_connection
    local_infile = frappe.conf.local_infile)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 325, in __init__
    self.connect()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 599, in connect
    self._request_authentication()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 861, in _request_authentication
    auth_packet = self._read_packet()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/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'@'172.19.0.6' (using password: YES)")

Note: I’m able to access maria db like so: docker exec -ti mysitecom_mariadb_1 bash and then mysql -u root -p and enter the root password set in .env to access the DBs:

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| _123-redacted-123  |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)

Does the following look correct? Should root have more host access than localhost?

MariaDB [(none)]> SELECT user,authentication_string,plugin,host FROM mysql.user;
+-------------------+-----------------------+--------+------------+
| user              | authentication_string | plugin | host       |
+-------------------+-----------------------+--------+------------+
| root              |                       |        | localhost  |
| _38f74ec15f7433a1 |                       |        | 172.19.0.4 |
| _38f74ec15f7433a1 |                       |        | %          |
+-------------------+-----------------------+--------+------------+
3 rows in set (0.000 sec)

Any direction would be greatly appreciated, thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:39 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
legend-zeratulcommented, Nov 28, 2021

The issue still exists. Local docker (swarm), using env.local, all volumes clean, mysql/mariadb root user name is ‘root’, all other components get deployed (not using traefik), site-creator fails when deployed from within docker-compose.yml because its unable to connect to the db - error is ‘access denied for user ‘root’, using password: yes’

However - the error seems to happen when site-creator is deployed from within the docker-compose.yml file - using ‘docker run’ from the command line works…!

Workaround that got the installation done for me:

  • Comment out the entire site-creator service in docker-compose.yml, bring down the stack if already running
  • Create an overlay network using: ‘docker network create --driver overlay --attachable <NW_NAME>’
  • Specify the above network in the docker-compose.yml file:
networks:
  default:
    external: true
    name: <NW_NAME>
  • Bring up the stack without site-creator
  • Run the site-creator from the command line using ‘docker run’ - full command below:
docker run \
    -e "SITE_NAME=$SITE_NAME" \
    -e "DB_ROOT_USER=$DB_ROOT_USER" \
    -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \
    -e "ADMIN_PASSWORD=$ADMIN_PASSWORD" \
    -e "INSTALL_APPS=erpnext" \
    -v <project-name>_sites-vol:/home/frappe/frappe-bench/sites \
    --network ${NW_NAME} \
    frappe/erpnext-worker:$VERSION new

In the above command, NW_NAME should be the same you specified in step 1 and in docker-compose.

Basic principles behind the workaround:

  • Site creator is not able to connect to mysql from within docker-compose, but can connect to mysql if run through docker run - I still dont know the reason for this, but all that we want is to get the instance up, while wiser folks look at the root cause…
  • Trying to run site creator using docker run without an attachable network will fail since site creator cannot connect to the default overlay network created for the stack deployed through docker compose
  • So we create an attachable network manually, tell docker to use this network when deploying the stack, and then run site creator manually from the command line

Hope that helps.

2reactions
parcelcatcommented, Apr 25, 2021

Found the issue! When following the single bench install instructions, the DB_ROOT_USER variable must remain on the default value of root in the .env file. This is because the mariadb image does not support changing the root username, and docker-compose.yml consequently does not set MariaDB’s root username to the DB_ROOT_USER value.

After deleting all of my volumes (with docker volume prune) and starting over with DB_ROOT_USER=root in .env, ERPNext is successfully installed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found