Mysql ErrorNo 22 on Site installation

Hello,

I’m getting the below error when trying to install a new site using command “bench --site site1.local install-app erpnext”. This is a new installation on Windows Linux SubSustem running Ubuntu.

I’m able to login into mysql through command line using user root and the password which I had set during installation.

Kindly help me with this error.

pymysql.err.OperationalError: (2003, “Can’t connect to MySQL server on u’localhost’ ([Errno 22] Invalid argument)”)

swadeesh@SWAD-PC:~/frappe-bench$ bench --site site1.local install-app erpnext
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
    main()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/commands/site.py", line 169, in install_app
    _install_app(app, verbose=context.verbose)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/installer.py", line 52, in install_app
    frappe.clear_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 555, in clear_cache
    frappe.cache_manager.clear_user_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/cache_manager.py", line 42, in clear_user_cache
    clear_global_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/cache_manager.py", line 48, in clear_global_cache
    clear_website_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/website/render.py", line 291, in clear_cache
    for method in frappe.get_hooks("website_clear_cache"):
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 931, in get_hooks
    hooks = _dict(cache().get_value("app_hooks", load_app_hooks))
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 79, in get_value
    val = generator()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 905, in load_app_hooks
    for app in [app_name] if app_name else get_installed_apps(sort=True):
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 869, in get_installed_apps
    installed = json.loads(db.get_global("installed_apps") or "[]")
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 692, in get_global
    return self.get_default(key, user)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 696, in get_default
    d = self.get_defaults(key, parent)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 714, in get_defaults
    defaults = frappe.defaults.get_defaults(parent)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/defaults.py", line 77, in get_defaults
    globald = get_defaults_for()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/defaults.py", line 204, in get_defaults_for
    where parent = %s order by creation""", (parent,), as_dict=1)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 122, in sql
    self.connect()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 75, in connect
    self._conn = self.get_connection()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 89, in get_connection
    local_infile = frappe.conf.local_infile)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 325, in __init__
    self.connect()
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 630, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on u'localhost' ([Errno 22] Invalid argument)")

Please help me with this.

Hi, seems like there is some issue with mysql or mariaDB. Is mariaDB properly installed?
Try typing bench mariadb in terminal inside frappe-bench and check if mariaDB connects.
if not then restart your mariadb service and try
The links below might help:-

https://comm.support.ca.com/kb/mysql-database-error-22-or-24/kb000048783

normally u is the prefix to the username, not the DB host machine as you have it here

I tried to delete frappe-bench directory and re-install frappe-bench using below command.

bench init frappe-bench && cd frappe-bench

I get the below error, but the process gets completed successfully.

ERROR: requests 2.21.0 has requirement urllib3<1.25,>=1.21.1, but you'll have urllib3 1.25.1 which is incompatible.
ERROR: botocore 1.12.137 has requirement urllib3<1.25,>=1.20; python_version == "2.7", but you'll have urllib3 1.25.1 which is incompatible.

Below warning is displayed on all bench commands.

/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.1) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)

And on " bench get-app erpnext GitHub - frappe/erpnext: Free and Open Source Enterprise Resource Planning (ERP)" I get error as below.

  ERROR: Could not find a version that satisfies the requirement unidecode (from erpnext==11.1.20) (from versions: none)
ERROR: No matching distribution found for unidecode (from erpnext==11.1.20)

I think I have some version mismatch error. Should I downgrade version of “urllib3” ?

@trentmu Update urllib3 to urllib3==1.25 in ~/frappe-bench/apps/frappe/requirements.txt

get error as “ERROR: requests 2.21.0 has requirement urllib3<1.25,>=1.21.1, but you'll have urllib3 1.25.2 which is incompatible.

Also get below on all bench commands.

Traceback (most recent call last):
  File "/usr/local/bin/bench", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3241, in <module>
    @_call_aside
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3225, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 585, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 598, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'urllib3<1.25,>=1.21.1' distribution was not found and is required by requests

In your case, you probably need to …
Modify the requirements.txt from
urllib3<1.25,>=1.21.1 (1st case) and urllib3<1.25,>=1.20
to
urllib3==1.25.2

I tried using 1.25.2 and got the same error.

To satisfy conditions of requests and botocore, update to 1.24.2. Had to execute “sudo pip install -q -e ./apps/frappe”.

Once that was done, “get-app erpnext” was also completed successfully.

I again get mysql error when trying to install erpnext app to site1.local.

swadeesh@SWAD-PC:~/frappe-bench$ bench --site site1.local install-app erpnext
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
    main()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/commands/site.py", line 169, in install_app
    _install_app(app, verbose=context.verbose)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/installer.py", line 52, in install_app
    frappe.clear_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 555, in clear_cache
    frappe.cache_manager.clear_user_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/cache_manager.py", line 42, in clear_user_cache
    clear_global_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/cache_manager.py", line 48, in clear_global_cache
    clear_website_cache()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/website/render.py", line 291, in clear_cache
    for method in frappe.get_hooks("website_clear_cache"):
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 931, in get_hooks
    hooks = _dict(cache().get_value("app_hooks", load_app_hooks))
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 79, in get_value
    val = generator()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 905, in load_app_hooks
    for app in [app_name] if app_name else get_installed_apps(sort=True):
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/__init__.py", line 869, in get_installed_apps
    installed = json.loads(db.get_global("installed_apps") or "[]")
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 692, in get_global
    return self.get_default(key, user)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 696, in get_default
    d = self.get_defaults(key, parent)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 714, in get_defaults
    defaults = frappe.defaults.get_defaults(parent)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/defaults.py", line 77, in get_defaults
    globald = get_defaults_for()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/defaults.py", line 204, in get_defaults_for
    where parent = %s order by creation""", (parent,), as_dict=1)
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 122, in sql
    self.connect()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 75, in connect
    self._conn = self.get_connection()
  File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 89, in get_connection
    local_infile = frappe.conf.local_infile)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 325, in __init__
    self.connect()
  File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 630, in connect
    raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on u'localhost' ([Errno 22] Invalid argument)")

I’m running out of options.

bench mariadb works fine.

This part is still wrong - I’m afraid I don’t know why, or how to fix that particular problem - in particular, if you’re using WLS. There are a couple of people that have gotten it to work (I think), but I don’t know WLS or ubuntu (I prefer manual debian installs).
Hopefully one of those guys who succeeded will see and respond to this post

I faced this issue. When you see this error, just restart Windows and do again, it will work.

1 Like

@trentmu Thanks for your help!

@lapphan Once I restarted my pc the error magically went away :open_mouth:

But I get the below issue on bench start

21:25:37 schedule.1       | Traceback (most recent call last):
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 69, in enqueue_events_for_all_sites
21:25:37 schedule.1       |     enqueue_events_for_site(site=site, queued_jobs=jobs_per_site[site])
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 101, in enqueue_events_for_site
21:25:37 schedule.1       |     log_and_raise()
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 89, in enqueue_events_for_site
21:25:37 schedule.1       |     if is_scheduler_disabled():
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/apps/frappe/frappe/utils/scheduler.py", line 233, in is_scheduler_disabled
21:25:37 schedule.1       |     return not frappe.utils.cint(frappe.db.get_single_value("System Settings", "enable_scheduler"))
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 547, in get_single_value
21:25:37 schedule.1       |     `tabSingles` where `doctype`=%s and `field`=%s""", (doctype, fieldname))
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/apps/frappe/frappe/database/database.py", line 156, in sql
21:25:37 schedule.1       |     self._cursor.execute(query, values)
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 170, in execute
21:25:37 schedule.1       |     result = self._query(query)
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 328, in _query
21:25:37 schedule.1       |     conn.query(q)
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 517, in query
21:25:37 schedule.1       |     self._affected_rows = self._read_query_result(unbuffered=unbuffered)
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 732, in _read_query_result
21:25:37 schedule.1       |     result.read()
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1075, in read
21:25:37 schedule.1       |     first_packet = self.connection._read_packet()
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 684, in _read_packet
21:25:37 schedule.1       |     packet.check_error()
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/protocol.py", line 220, in check_error
21:25:37 schedule.1       |     err.raise_mysql_exception(self._data)
21:25:37 schedule.1       |   File "/home/swadeesh/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
21:25:37 schedule.1       |     raise errorclass(errno, errval)
21:25:37 schedule.1       | ProgrammingError: (1146, u"Table '_6d4b9452aef14153.tabSingles' doesn't exist")

Missing tables implies an out of sync system vs. DB schema. A bench migrate should fix it, followed by a bench update. In all it seems that the DB error prevented the install from completing properly

@trentmu It looks like the bench manager was pointing to an older DB which did not have tables. Fixed it to point to the latest DB and it started working.

I’m now able to setup and run the system :slight_smile:

All it took was to restart windows to fix the "Can't connect to MySQL server on u'localhost' ([Errno 22] Invalid argument)") issue.

Thanks for your help.