Tag Archives: Sync keystone database error

[Install OpenStack] Sync keystone database error: keystone DBConnectionError: (pymysql.err.OperationalError) (2003, “Can’t connect to MySQL server on ‘controller’ ([Errno 111] Connection refused)”)

Execute the command su -s /bin/sh -c “keystone-manage db_sync” keystone keeps failing to execute, check /var/log/keystone/keystone.log and find the following error:
2021-09-27 09:05:18.381 185184 ERROR keystone Traceback (most recent call last):
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/bin/keystone-manage”, line 10, in <module>
2021-09-27 09:05:18.381 185184 ERROR keystone sys.exit(main())
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/keystone/cmd/manage.py”, line 44, in main
2021-09-27 09:05:18.381 185184 ERROR keystone cli.main(argv=sys.argv, config_files=config_files)
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/keystone/cmd/cli.py”, line 1312, in main
2021-09-27 09:05:18.381 185184 ERROR keystone CONF.command.cmd_class.main()
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/keystone/cmd/cli.py”, line 467, in main
2021-09-27 09:05:18.381 185184 ERROR keystone CONF.command.version)
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/keystone/common/sql/upgrades.py”, line 251, in offline_sync_database_t o_version
2021-09-27 09:05:18.381 185184 ERROR keystone expand_schema()
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/keystone/common/sql/upgrades.py”, line 271, in expand_schema
2021-09-27 09:05:18.381 185184 ERROR keystone _sync_common_repo(version=None)
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/keystone/common/sql/upgrades.py”, line 167, in _sync_common_repo
2021-09-27 09:05:18.381 185184 ERROR keystone with sql.session_for_write() as session:
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib64/python2.7/contextlib.py”, line 17, in __enter__
2021-09-27 09:05:18.381 185184 ERROR keystone return self.gen.next()
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py”, line 944, in _transaction_scope
2021-09-27 09:05:18.381 185184 ERROR keystone allow_async=self._allow_async) as resource:
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib64/python2.7/contextlib.py”, line 17, in __enter__
2021-09-27 09:05:18.381 185184 ERROR keystone return self.gen.next()
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py”, line 558, in _session
2021-09-27 09:05:18.381 185184 ERROR keystone bind=self.connection, mode=self.mode)
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py”, line 317, in _create_session
2021-09-27 09:05:18.381 185184 ERROR keystone self._start()
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py”, line 403, in _start
2021-09-27 09:05:18.381 185184 ERROR keystone engine_args, maker_args)
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py”, line 427, in _setup_for_connectio n
2021-09-27 09:05:18.381 185184 ERROR keystone sql_connection=sql_connection, **engine_kwargs)
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/engines.py”, line 155, in create_engine
2021-09-27 09:05:18.381 185184 ERROR keystone test_conn = _test_connection(engine, max_retries, retry_interval)
2021-09-27 09:05:18.381 185184 ERROR keystone File “/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/engines.py”, line 339, in _test_connection
2021-09-27 09:05:18.381 185184 ERROR keystone six.reraise(type(de_ref), de_ref)
2021-09-27 09:05:18.381 185184 ERROR keystone File “<string>”, line 2, in reraise
2021-09-27 09:05:18.381 185184 ERROR keystone DBConnectionError: (pymysql.err.OperationalError) (2003, “Can’t connect to MySQL server on ‘controller’ ([Errno 111] Connection refused)”)
2021-09-27 09:05:18.381 185184 ERROR keystone
2021-09-27 10:09:09.147 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 10 attempts left.
2021-09-27 10:09:19.158 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 9 attempts left.
2021-09-27 10:09:29.169 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 8 attempts left.
2021-09-27 10:09:39.181 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 7 attempts left.
2021-09-27 10:09:49.193 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 6 attempts left.
2021-09-27 10:09:59.204 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 5 attempts left.
2021-09-27 10:10:09.216 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 4 attempts left.
2021-09-27 10:10:19.228 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 3 attempts left.
2021-09-27 10:10:29.240 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 2 attempts left.
2021-09-27 10:10:39.251 165810 WARNING oslo_db.sqlalchemy.engines [-] SQL connection failed. 1 attempts left.
2021-09-27 10:10:49.255 165810 CRITICAL keystone [-] DBConnectionError: (pymysql.err.OperationalError) (2003, “Can’t connect to MySQL server on ‘controller’ ([Errno 111] Connection refused)”)
Type the log at the end of the error report
Looking at the keystone logs again, you can see that the execution is now as follows
After searching the internet the format should be
engine(“mysql+pymysql://{user}:{password}@{host}:{port}/ajx?charset=utf8”.format(**config))
It’s easy to see that the port is missing

Modify /etc/keystone/keystone.conf to add the port


Execute the sync command again