mysql

The mysql connection can be used to access a MySQL database.

connection "mysql" "my_connection" {
host = "localhost"
port = 3306
db = "mydb"
username = "myuser"
password = "mypassword123"
}

Arguments

NameTypeRequired?Description
dbStringOptionalDatabase name. Defaults to mysql.
hostStringOptionalDatabase hostname. Defaults to localhost.
passwordStringOptionalDatabase password.
portNumberOptionalDatabase port. Defaults to 3306.
usernameStringOptionalDatabase username. Defaults to root.

All arguments are optional, and a mysql connection with no arguments will behave the same as the default connection.

Attributes (Read-Only)

AttributeTypeDescription
connection_stringStringThe connection string built from the arguments to this connection, in the format mysql://[username[:password]@][host][:port][/db]

Default Connection

The mysql connection type includes an implicit, default connection (connection.mysql.default) that will be configured using the following default values:

connection "mysql" "default" {
db = "mysql"
host = "localhost"
password = ""
port = 3306
username = "root"
}