diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 30c1f43d4..310a84308 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,3 @@ ### 合并描述 -- [ ] 我添加了测试用例来覆盖新代码。 +- 我添加了测试用例来覆盖新代码。 diff --git a/plugins/mysql-apt/class/mysqlDb.py b/plugins/mysql-apt/class/mysqlDb.py deleted file mode 100755 index aa96b0278..000000000 --- a/plugins/mysql-apt/class/mysqlDb.py +++ /dev/null @@ -1,91 +0,0 @@ -# coding: utf-8 - -import re -import os -import sys - -sys.path.append(os.getcwd() + "/class/core") -import mw - - -class mysqlDb: - __DB_PASS = None - __DB_USER = 'root' - __DB_PORT = 3306 - __DB_HOST = 'localhost' - __DB_CONN = None - __DB_CUR = None - __DB_ERR = None - __DB_CNF = '/etc/my.cnf' - - def __Conn(self): - '''连接MYSQL数据库''' - try: - import mw - socket = '/www/server/mysql-ya/mysql.sock' - try: - import MySQLdb - except Exception as ex: - # print('dd') - self.__DB_ERR = ex - return False - try: - myconf = mw.readFile(self.__DB_CNF) - rep = "port\s*=\s*([0-9]+)" - self.__DB_PORT = int(re.search(rep, myconf).groups()[0]) - except: - self.__DB_PORT = 3306 - # print self.__DB_PASS - #self.__DB_PASS = mw.M('config').where('id=?', (1,)).getField('mysql_root') - try: - self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, - port=self.__DB_PORT, charset="utf8", connect_timeout=1, unix_socket=socket) - except MySQLdb.Error as e: - self.__DB_HOST = '127.0.0.1' - self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS, - port=self.__DB_PORT, charset="utf8", connect_timeout=1, unix_socket=socket) - self.__DB_CUR = self.__DB_CONN.cursor() - return True - except MySQLdb.Error as e: - self.__DB_ERR = e - return False - - def setDbConf(self, conf): - self.__DB_CNF = conf - - def setPwd(self, pwd): - self.__DB_PASS = pwd - - def getPwd(self): - return self.__DB_PASS - - def execute(self, sql): - # 执行SQL语句返回受影响行 - if not self.__Conn(): - return self.__DB_ERR - try: - result = self.__DB_CUR.execute(sql) - self.__DB_CONN.commit() - self.__Close() - return result - except Exception as ex: - return ex - - def query(self, sql): - # 执行SQL语句返回数据集 - if not self.__Conn(): - return self.__DB_ERR - try: - self.__DB_CUR.execute(sql) - result = self.__DB_CUR.fetchall() - # 将元组转换成列表 - # data = list(map(list, result)) - self.__Close() - return result - except Exception as ex: - return ex - - # 关闭连接 - def __Close(self): - self.__DB_CUR.close() - self.__DB_CONN.close() diff --git a/plugins/mysql-apt/conf/my5.7.cnf b/plugins/mysql-apt/conf/my5.7.cnf index 847bc276e..e8379b24a 100644 --- a/plugins/mysql-apt/conf/my5.7.cnf +++ b/plugins/mysql-apt/conf/my5.7.cnf @@ -8,8 +8,8 @@ default-character-set = UTF8MB4 [mysqld] pid-file = {$SERVER_APP_PATH}/data/mysql.pid user = mysql -port = 3376 -mysqlx_port = 33760 +port = 33206 +mysqlx_port = 33260 socket = {$SERVER_APP_PATH}/mysql.sock datadir = {$SERVER_APP_PATH}/data log-error = {$SERVER_APP_PATH}/data/error.log diff --git a/plugins/mysql-apt/conf/my8.0.cnf b/plugins/mysql-apt/conf/my8.0.cnf index 934657c4b..8488245cb 100644 --- a/plugins/mysql-apt/conf/my8.0.cnf +++ b/plugins/mysql-apt/conf/my8.0.cnf @@ -1,7 +1,7 @@ [client] user = root #password = your_password -port = 3386 +port = 3306 socket = {$SERVER_APP_PATH}/mysql.sock default-character-set = UTF8MB4 @@ -9,8 +9,8 @@ default-character-set = UTF8MB4 default_authentication_plugin=mysql_native_password pid-file = {$SERVER_APP_PATH}/data/mysql.pid user = mysql -port = 3386 -mysqlx_port = 33860 +port = 33206 +mysqlx_port = 33260 socket = {$SERVER_APP_PATH}/mysql.sock datadir = {$SERVER_APP_PATH}/data log-error = {$SERVER_APP_PATH}/data/error.log diff --git a/plugins/mysql-apt/index.py b/plugins/mysql-apt/index.py index 784c32597..3f7d4d9a8 100755 --- a/plugins/mysql-apt/index.py +++ b/plugins/mysql-apt/index.py @@ -35,9 +35,6 @@ def getPluginName(): def getPluginDir(): return mw.getPluginDir() + '/' + getPluginName() -sys.path.append(getPluginDir() + "/class") -import mysqlDb - def getServerDir(): return mw.getServerDir() + '/' + getPluginName() @@ -86,7 +83,7 @@ def checkArgs(data, ck=[]): def getConf(): - path = '/etc/mysql/mysql.conf.d/mysqld.cnf' + path = '/etc/mysql/my.cnf' return path @@ -120,11 +117,15 @@ def pSqliteDb(dbname='databases'): def pMysqlDb(): - db = mysqlDb.mysqlDb() - db.__DB_CNF = getConf() - db.setDbConf(getConf()) - db.setPwd(pSqliteDb('config').where( - 'id=?', (1,)).getField('mysql_root')) + # pymysql + db = mw.getMyORM() + # MySQLdb | + # db = mw.getMyORMDb() + + db.setPort(getDbPort()) + db.setSocket(getSocketFile()) + # db.setCharset("utf8") + db.setPwd(pSqliteDb('config').where('id=?', (1,)).getField('mysql_root')) return db @@ -146,6 +147,10 @@ def initDreplace(version=''): content = contentReplace(content) mw.writeFile(mysql_conf, content) + # lock_file = getServerDir() + "/installed.pl" + # if not os.path.exists(lock_file): + # mw.writeFile(lock_file, "ok") + # systemd systemDir = mw.systemdCfgDir() systemService = systemDir + '/mysql-apt.service' diff --git a/plugins/mysql-apt/init.d/mysql.service.tpl b/plugins/mysql-apt/init.d/mysql.service.tpl index a068c3716..a886e40b5 100644 --- a/plugins/mysql-apt/init.d/mysql.service.tpl +++ b/plugins/mysql-apt/init.d/mysql.service.tpl @@ -35,8 +35,8 @@ WantedBy=multi-user.target User=mysql Group=mysql Type=notify -ExecStartPre=+/usr/share/mysql-8.0/mysql-systemd-start pre -ExecStart=/usr/sbin/mysqld +#ExecStartPre=+/usr/share/mysql-8.0/mysql-systemd-start pre +ExecStart=/usr/sbin/mysqld --defaults-file={$SERVER_PATH}/mysql-apt/etc/my.cnf TimeoutSec=0 LimitNOFILE = 10000 Restart=on-failure