I’m trying to automate the setup of a MySQL database using Terraform for my project hosted on Google Cloud Platform (GCP). However, I’m encountering an issue when attempting to execute a SQL script that requires the SYSTEM_USER privilege. The error message I’m receiving is as follows:
Error running command ‘mysql -h <IP_ADDRESS> -P 3306 -u root -p < ./database.sql’: exit status 1. Output: mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1227 (42000) at line 510: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
resource "google_sql_database_instance" "mysql_instance" {
name = var.instance_name
database_version = "MYSQL_8_0"
region = "us-central1"
root_password = var.password
settings {
disk_autoresize = "false"
disk_size = "10"
disk_type = "PD_SSD"
tier = "db-n1-standard-1"
ip_configuration {
ipv4_enabled = "true"
dynamic "authorized_networks" {
for_each = var.cloud_sql.authorized_networks
iterator = network
content {
name = "ip-${network.key}"
value = network.value
}
}
}
}
}
resource "google_sql_database" "database" {
name = "cloud_sql_db"
instance = google_sql_database_instance.mysql_instance.name
provisioner "local-exec" {
command = "mysql -h ${google_sql_database_instance.mysql_instance.public_ip_address} -P 3306 -u root -p${google_sql_database_instance.mysql_instance.root_password} ${google_sql_database.database.name} < ${var.sql_script}"
}
}
resource "google_sql_user" "users" {
name = "root"
instance = google_sql_database_instance.mysql_instance.name
host = "%"
password = google_sql_database_instance.mysql_instance.root_password
}