#241·PyMySQL

change_user

Author: ghostCreated May 21, 2014Updated Apr 11, 2019

Would you please add the following API like mysql-python for compatibility? change_user() set_character_set() The sample implementation below for reference

bash
*** connections.py.orig 2014-05-21 11:36:59.176700393 +0900
--- connections.py  2014-05-21 11:36:49.020550346 +0900
***************
*** 968,971 ****
--- 968,1017 ----
              if DEBUG: auth_packet.dump()

+     def _request_change_user(self):
+         if self.user is None:
+             raise ValueError("Dit not specify a username to change")
+ 
+         if isinstance(self.user, text_type):
+             self.user = self.user.encode(self.encoding)
+ 
+         data = int2byte(COM_CHANGE_USER) + self.user + b'\0' + \
+                _scramble(self.password.encode('latin1'), self.salt)
+ 
+         if self.db is not None:
+             if isinstance(self.db, text_type):
+                 self.db = self.db.encode(self.encoding)
+             data += self.db + int2byte(0)
+         else:
+             data += int2byte(0)
+ 
+         data = struct.pack("<i",len(data)) + data
+ 
+         self._write_bytes(data)
+         self._read_query_result()
+ 
+     def change_user(self,user=None,passwd=None,db=None):
+         if user is None:
+             user = self.user
+         if passwd is None:
+             passwd = self.passwd
+         if db is None:
+             db = self.db
+         save_user = self.user
+         save_passwd = self.password
+         save_db = self.db
+         try:
+             self.user = user
+             self.passwd = passwd
+             self.db = db
+             self._request_change_user()
+         except:
+             self.user = save_user
+             self.passwd = save_passwd
+             self.db = save_db
+             raise
+ 
+     def set_character_set(self,charset):
+         self.set_charset(charset)
+ 
      # _mysql support
      def thread_id(self):