From a13ae41134699d4ef1b8ba68fdc01bbd9a1705d5 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 27 Nov 2009 20:19:43 +0800 Subject: [PATCH] Fix MySQL startup error: 2002 2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)" --- pyfpdb/Exceptions.py | 7 +++++++ pyfpdb/fpdb.py | 4 ++++ pyfpdb/fpdb_db.py | 2 ++ 3 files changed, 13 insertions(+) diff --git a/pyfpdb/Exceptions.py b/pyfpdb/Exceptions.py index 87015e3e..5b4f4391 100644 --- a/pyfpdb/Exceptions.py +++ b/pyfpdb/Exceptions.py @@ -27,5 +27,12 @@ class FpdbMySQLAccessDenied(FpdbDatabaseError): def __str__(self): return repr(self.value +" " + self.errmsg) +class FpdbMySQLNoDatabase(FpdbDatabaseError): + def __init__(self, value='', errmsg=''): + self.value = value + self.errmsg = errmsg + def __str__(self): + return repr(self.value +" " + self.errmsg) + class DuplicateError(FpdbError): pass diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 80d3fb93..9de449c9 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -473,6 +473,10 @@ class fpdb: except Exceptions.FpdbMySQLAccessDenied: self.warning_box("MySQL Server reports: Access denied. Are your permissions set correctly?") exit() + except Exceptions.FpdbMySQLNoDatabase: + msg = "MySQL client reports: 2002 error. Unable to connect - Please check that the MySQL service has been started" + self.warning_box(msg) + exit # except FpdbMySQLFailedError: # self.warning_box("Unable to connect to MySQL! Is the MySQL server running?!", "FPDB ERROR") diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index a58606be..8a0ec54e 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -106,6 +106,8 @@ class fpdb_db: except MySQLdb.Error, ex: if ex.args[0] == 1045: raise FpdbMySQLAccessDenied(ex.args[0], ex.args[1]) + elif ex.args[0] == 2002: + raise FpdbMySQLNoDatabase(ex.args[0], ex.args[1]) else: print "*** WARNING UNKNOWN MYSQL ERROR", ex elif backend == fpdb_db.PGSQL: