Internal server error and Errno 111 connection refused

Hi tried a couple of solutions mentioned in the forum but nothing worked. could someone please give me a solution to fix this issue.

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/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, 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/local/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/frappe/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/frappe/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/frappe/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/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/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/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 302, in backup
    odb = scheduled_backup(ignore_files=not with_files, backup_path_db=backup_path_db, backup_path_files=backup_path_files, backup_path_private_files=backup_path_private_files, force=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/backups.py", line 170, in scheduled_backup
    odb = new_backup(older_than, ignore_files, backup_path_db=backup_path_db, backup_path_files=backup_path_files, force=force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/backups.py", line 180, in new_backup
    odb.get_backup(older_than, ignore_files, force=force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/backups.py", line 48, in get_backup
    self.set_backup_file_name()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/backups.py", line 61, in set_backup_file_name
    todays_date = now_datetime().strftime('%Y%m%d_%H%M%S')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/data.py", line 126, in now_datetime
    dt = convert_utc_to_user_timezone(datetime.datetime.utcnow())
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/data.py", line 149, in convert_utc_to_user_timezone
    return utcnow.astimezone(timezone(get_time_zone()))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/data.py", line 143, in get_time_zone
    return frappe.cache().get_value("time_zone", _get_time_zone)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 79, in get_value
    val = generator()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/data.py", line 137, in _get_time_zone
    return frappe.db.get_system_setting('time_zone') or 'Asia/Kolkata' # Default to India ?!
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 950, in get_system_setting
    return frappe.cache().get_value("system_settings", _load_system_settings).get(key)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py", line 79, in get_value
    val = generator()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 949, in _load_system_settings
    return self.get_singles_dict("System Settings")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 610, in get_singles_dict
    """, doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 165, in sql
    self.connect()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database.py", line 115, in connect
    charset='utf8mb4', use_unicode = True, conv = conversions, local_infile = self.local_infile)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 325, in __init__
    self.connect()
  File "/home/frappe/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 111] Connection refused)")

You have a mysql permission problem, try this

mysql -uroot -pYourMYSQLpasswordOfChoice -Bse "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.%.%.%' IDENTIFIED BY 'YourMYSQLpasswordOfChoice' WITH GRANT OPTION;"
mysql -uroot -pYourMYSQLpasswordOfChoice -Bse "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'YourMYSQLpasswordOfChoice' WITH GRANT OPTION;"
mysql -uroot -pYourMYSQLpasswordOfChoice -Bse "GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.%.%' IDENTIFIED BY 'YourMYSQLpasswordOfChoice' WITH GRANT OPTION;"

@trentmu Thanks for the solution you suggested. In my case, the problem is a corrupt database :disappointed_relieved:.

You have backups?

Thanks your solution it worked for problem below:

OperationalError: (2003, “Can’t connect to MySQL server on u’localhost’ ([Errno 111] Connection refused)”)