當前位置: 首頁>>代碼示例>>Python>>正文


Python cymysql.connect方法代碼示例

本文整理匯總了Python中cymysql.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python cymysql.connect方法的具體用法?Python cymysql.connect怎麽用?Python cymysql.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cymysql的用法示例。


在下文中一共展示了cymysql.connect方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pull_db_all_user

# 需要導入模塊: import cymysql [as 別名]
# 或者: from cymysql import connect [as 別名]
def pull_db_all_user(self):
		import cymysql
		#數據庫所有用戶信息
		if self.cfg["ssl_enable"] == 1:
			conn = cymysql.connect(host=self.cfg["host"], port=self.cfg["port"],
					user=self.cfg["user"], passwd=self.cfg["password"],
					db=self.cfg["db"], charset='utf8',
					ssl={'ca':self.cfg["ssl_ca"],'cert':self.cfg["ssl_cert"],'key':self.cfg["ssl_key"]})
		else:
			conn = cymysql.connect(host=self.cfg["host"], port=self.cfg["port"],
					user=self.cfg["user"], passwd=self.cfg["password"],
					db=self.cfg["db"], charset='utf8')

		try:
			rows = self.pull_db_users(conn)
		finally:
			conn.close()

		if not rows:
			logging.warn('no user in db')
		return rows 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:23,代碼來源:db_transfer.py

示例2: pull_db_all_user

# 需要導入模塊: import cymysql [as 別名]
# 或者: from cymysql import connect [as 別名]
def pull_db_all_user(self):
		import cymysql
		#數據庫所有用戶信息
		if self.cfg["ssl_enable"] == 1:
			conn = cymysql.connect(host=self.cfg["host"], port=self.cfg["port"],
					user=self.cfg["user"], passwd=self.cfg["password"],
					db=self.cfg["db"], charset='utf8',
					ssl={'ca':self.cfg["ssl_ca"],'cert':self.cfg["ssl_cert"],'key':self.cfg["ssl_key"]})
		else:
			conn = cymysql.connect(host=self.cfg["host"], port=self.cfg["port"],
					user=self.cfg["user"], passwd=self.cfg["password"],
					db=self.cfg["db"], charset='utf8')

		rows = self.pull_db_users(conn)
		conn.close()
		if not rows:
			logging.warn('no user in db')
		return rows 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:20,代碼來源:db_transfer.py

示例3: run_command

# 需要導入模塊: import cymysql [as 別名]
# 或者: from cymysql import connect [as 別名]
def run_command(self, command, id):
        value = subprocess.check_output(command.split(' ')).decode('utf-8')
        if configloader.get_config().API_INTERFACE == 'modwebapi':
            global webapi
            webapi.postApi('func/autoexec', {'node_id': configloader.get_config().NODE_ID}, {'data': [{'value': 'NodeID:' + str(configloader.get_config(
            ).NODE_ID) + ' Exec Command ID:' + str(configloader.get_config().NODE_ID) + " Result:\n" + str(value), 'sign': str(value), 'type': 2}]})
        else:
            import cymysql
            conn = cymysql.connect(
                host=configloader.get_config().MYSQL_HOST,
                port=configloader.get_config().MYSQL_PORT,
                user=configloader.get_config().MYSQL_USER,
                passwd=configloader.get_config().MYSQL_PASS,
                db=configloader.get_config().MYSQL_DB,
                charset='utf8')
            conn.autocommit(True)
            cur = conn.cursor()
            cur.execute(
                "INSERT INTO `auto` (`id`, `value`, `sign`, `datetime`,`type`) VALUES (NULL, 'NodeID:" +
                str(
                    configloader.get_config().NODE_ID) +
                " Result:\n" +
                str(value) +
                "', 'NOT', unix_timestamp(),'2')")
            rows = cur.fetchall()
            cur.close()
            conn.close() 
開發者ID:PaperDashboard,項目名稱:shadowsocks,代碼行數:29,代碼來源:auto_thread.py

示例4: update_all_user

# 需要導入模塊: import cymysql [as 別名]
# 或者: from cymysql import connect [as 別名]
def update_all_user(self, dt_transfer):
		import cymysql
		update_transfer = {}
		
		query_head = 'UPDATE user'
		query_sub_when = ''
		query_sub_when2 = ''
		query_sub_in = None
		last_time = time.time()

		for id in dt_transfer.keys():
			transfer = dt_transfer[id]
			#小於最低更新流量的先不更新
			update_trs = 1024 * (2048 - self.user_pass.get(id, 0) * 64)
			if transfer[0] + transfer[1] < update_trs and id not in self.force_update_transfer:
				self.user_pass[id] = self.user_pass.get(id, 0) + 1
				continue
			if id in self.user_pass:
				del self.user_pass[id]

			query_sub_when += ' WHEN %s THEN u+%s' % (id, int(transfer[0] * self.cfg["transfer_mul"]))
			query_sub_when2 += ' WHEN %s THEN d+%s' % (id, int(transfer[1] * self.cfg["transfer_mul"]))
			update_transfer[id] = transfer

			if query_sub_in is not None:
				query_sub_in += ',%s' % id
			else:
				query_sub_in = '%s' % id

		if query_sub_when == '':
			return update_transfer
		query_sql = query_head + ' SET u = CASE port' + query_sub_when + \
					' END, d = CASE port' + query_sub_when2 + \
					' END, t = ' + str(int(last_time)) + \
					' WHERE port IN (%s)' % query_sub_in
		if self.cfg["ssl_enable"] == 1:
			conn = cymysql.connect(host=self.cfg["host"], port=self.cfg["port"],
					user=self.cfg["user"], passwd=self.cfg["password"],
					db=self.cfg["db"], charset='utf8',
					ssl={'ca':self.cfg["ssl_ca"],'cert':self.cfg["ssl_cert"],'key':self.cfg["ssl_key"]})
		else:
			conn = cymysql.connect(host=self.cfg["host"], port=self.cfg["port"],
					user=self.cfg["user"], passwd=self.cfg["password"],
					db=self.cfg["db"], charset='utf8')

		cur = conn.cursor()
		cur.execute(query_sql)
		cur.close()
		conn.commit()
		conn.close()
		return update_transfer 
開發者ID:AlphaBrock,項目名稱:ssr-ml,代碼行數:53,代碼來源:db_transfer.py


注:本文中的cymysql.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。