2015-12-17 02:59:35 +01:00
---
layout: "mysql"
page_title: "Provider: MySQL"
sidebar_current: "docs-mysql-index"
description: |-
A provider for MySQL Server.
---
# MySQL Provider
[MySQL ](http://www.mysql.com ) is a relational database server. The MySQL
provider exposes resources used to manage the configuration of resources
in a MySQL server.
Use the navigation to the left to read about the available resources.
## Example Usage
The following is a minimal example:
2017-04-08 01:58:01 +02:00
```hcl
2015-12-17 02:59:35 +01:00
# Configure the MySQL provider
provider "mysql" {
2017-02-18 23:48:50 +01:00
endpoint = "my-database.example.com:3306"
username = "app-user"
password = "app-password"
2015-12-17 02:59:35 +01:00
}
# Create a Database
resource "mysql_database" "app" {
2017-02-18 23:48:50 +01:00
name = "my_awesome_app"
2015-12-17 02:59:35 +01:00
}
```
This provider can be used in conjunction with other resources that create
MySQL servers. For example, ``aws_db_instance`` is able to create MySQL
servers in Amazon's RDS service.
2017-04-08 01:58:01 +02:00
```hcl
2015-12-17 02:59:35 +01:00
# Create a database server
resource "aws_db_instance" "default" {
2017-02-18 23:48:50 +01:00
engine = "mysql"
engine_version = "5.6.17"
instance_class = "db.t1.micro"
name = "initial_db"
username = "rootuser"
password = "rootpasswd"
# etc, etc; see aws_db_instance docs for more
2015-12-17 02:59:35 +01:00
}
# Configure the MySQL provider based on the outcome of
# creating the aws_db_instance.
provider "mysql" {
2017-02-18 23:48:50 +01:00
endpoint = "${aws_db_instance.default.endpoint}"
username = "${aws_db_instance.default.username}"
password = "${aws_db_instance.default.password}"
2015-12-17 02:59:35 +01:00
}
# Create a second database, in addition to the "initial_db" created
# by the aws_db_instance resource above.
resource "mysql_database" "app" {
2017-02-18 23:48:50 +01:00
name = "another_db"
2015-12-17 02:59:35 +01:00
}
```
## Argument Reference
The following arguments are supported:
* `endpoint` - (Required) The address of the MySQL server to use. Most often a "hostname:port" pair, but may also be an absolute path to a Unix socket when the host OS is Unix-compatible.
* `username` - (Required) Username to use to authenticate with the server.
* `password` - (Optional) Password for the given user, if that user has a password.