Hello, I would like to know if there is a way to execute a script that inserts the same record 100 times and this is replicated in several mysql servers.
I made this script in python
import pymysql
try:
conexion = pymysql.connect(host='172.16.2.9',
user='anonimo',
password='hola',
db='calificaciones')
try:
with conexion.cursor() as cursor:
for consulta in range(1,10001):
consulta = "INSERT INTO pbd2019 VALUES (%s, %s, %s);"
cursor.execute(consulta, ("216411051","Frank Miller", 100))
conexion.commit()
finally:
conexion.close()
except (pymysql.err.OperationalError, pymysql.err.InternalError) as e:
print("Ocurrió un error al conectar: ", e)
And if it works for only one host and I have the doubt that if the same script can be executed to several mysql servers using the same user.
For example all mysql servers on the 172.16.2.x network can run the script at the same time
UPDATE:
Here is a script which prints all the ip addresses of the network segment 172.16.2.0
import ipaddress
red_ipv4 = ipaddress.ip_network('172.16.2.0/24')
d = ipaddress.ip_address('172.16.2.0')
for d in red_ipv4:
print(d)
print()
Once having the ip addresses in theory, it would only be that in the host attribute of the connection to mysql it would be replaced by the values returned from the ip script, right?
the solution to what you expose is to create some iterator of hostnames, and do the operations on this set. In this case, they correspond to IP addresses, so the solution could be something like this.
Now, since the operations happen on different hosts, you could do it concurrently using an asynchronous map , to make it faster.
The script was as follows