mirror of
				https://github.com/ansible-collections/community.mysql.git
				synced 2025-10-25 05:24:01 -07:00 
			
		
		
		
	Add IF EXISTS clause to DROP USER statement (#309)
This commit is contained in:
		
					parent
					
						
							
								b0de252ce2
							
						
					
				
			
			
				commit
				
					
						59d411ac82
					
				
			
		
					 2 changed files with 6 additions and 1 deletions
				
			
		|  | @ -0,0 +1,2 @@ | |||
| bugfixes: | ||||
| - "mysql_user - fix the possibility for a race condition that breaks certain (circular) replication configurations when ``DROP USER`` is executed on multiple nodes in the replica set. Adding ``IF EXISTS`` avoids the need to use ``sql_log_bin: no`` making the statement always replication safe (https://github.com/ansible-collections/community.mysql/pull/287)." | ||||
|  | @ -704,7 +704,10 @@ def user_delete(cursor, user, host, host_all, check_mode): | |||
|         hostnames = [host] | ||||
| 
 | ||||
|     for hostname in hostnames: | ||||
|         cursor.execute("DROP USER %s@%s", (user, hostname)) | ||||
|         try: | ||||
|             cursor.execute("DROP USER IF EXISTS %s@%s", (user, hostname)) | ||||
|         except Exception: | ||||
|             cursor.execute("DROP USER %s@%s", (user, hostname)) | ||||
| 
 | ||||
|     return True | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue