Делаю вот так:
import os
from mysql.connector import connect, Error
MYSQL_PASSWORD = os.environ.get("MYSQL_ROOT_PASSWORD")
try:
cnx = connect(user="root", password=MYSQL_PASSWORD, host="mysql")
with open('bootstrap.sql', 'r') as sql:
with cnx.cursor() as cursor:
cursor.execute(sql.read(), multi=True)
cnx.commit()
except Error as err:
print("Error: " + err)
exit(1)
Сам sql простой:
CREATE DATABASE IF NOT EXISTS db1 character set utf8 collate utf8_general_ci;
CREATE DATABASE IF NOT EXISTS db2 character set utf8 collate utf8_general_ci;
CREATE DATABASE IF NOT EXISTS db3 character set utf8 collate utf8_general_ci;
CREATE DATABASE IF NOT EXISTS db4 character set utf8 collate utf8_general_ci;
CREATE DATABASE IF NOT EXISTS db5 character set utf8 collate utf8_general_ci;
CREATE DATABASE IF NOT EXISTS db6 character set utf8 collate utf8_general_ci;
CREATE DATABASE IF NOT EXISTS db7 character set utf8 collate utf8_general_ci;
CREATE USER IF NOT EXISTS `user%`@`%` IDENTIFIED BY 'password';
GRANT SELECT,INSERT,UPDATE ON db1.* TO `user%`@`%`;
GRANT SELECT,INSERT,UPDATE ON db2.* TO `user%`@`%`;
GRANT SELECT,INSERT,UPDATE ON db3.* TO `user%`@`%`;
GRANT SELECT,INSERT,UPDATE ON db4.* TO `user%`@`%`;
GRANT SELECT,INSERT,UPDATE ON db5.* TO `user%`@`%`;
GRANT SELECT,INSERT,UPDATE ON db6.* TO `user%`@`%`;
GRANT SELECT,INSERT,UPDATE ON db7.* TO `user%`@`%`;
В итоге скрипт просто выходит с нулём и ничего не делает. Понять не могу что не так.