Skip to content
Docs Try Aspire

MySqlBuilderExtensions Methods

Class Methods 10 members
Provides extension methods for adding MySQL resources to an Hosting.IDistributedApplicationBuilder.
AddDatabase(IResourceBuilder<MySqlServerResource>, string, string?) Section titled AddDatabase(IResourceBuilder<MySqlServerResource>, string, string?) extension IResourceBuilder<MySqlDatabaseResource>
Adds a MySQL database to the application model.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlDatabaseResource> AddDatabase(
this IResourceBuilder<MySqlServerResource> builder,
string name,
string? databaseName = null)
{
// ...
}
}
builder IResourceBuilder<MySqlServerResource> The MySQL server resource builder.
name string The name of the resource. This name will be used as the connection string name when referenced in a dependency.
databaseName string? optional The name of the database. If not provided, this defaults to the same value as name.
IResourceBuilder<MySqlDatabaseResource> A reference to the ApplicationModel.IResourceBuilder`1.

When adding a MySqlDatabaseResource to your application model the resource can then be referenced by other resources using the resource name. When the dependent resource is using the extension method ResourceBuilderExtensions.WaitFor then the dependent resource will wait until the MySQL database is available.

Note that calling MySqlBuilderExtensions.AddDatabase will result in the database being created on the MySQL server when the server becomes ready. The database creation happens automatically as part of the resource lifecycle.

AddMySql(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, int?) Section titled AddMySql(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, int?) extension IResourceBuilder<MySqlServerResource>
Adds a MySQL server resource to the application model. For local development a container is used.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlServerResource> AddMySql(
this IDistributedApplicationBuilder builder,
string name,
IResourceBuilder<ParameterResource>? password = null,
int? port = null)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder.
name string The name of the resource. This name will be used as the connection string name when referenced in a dependency.
password IResourceBuilder<ParameterResource> optional The parameter used to provide the root password for the MySQL resource. If null a random password will be generated.
port int? optional The host port for MySQL.
IResourceBuilder<MySqlServerResource> A reference to the ApplicationModel.IResourceBuilder`1.
This version of the package defaults to the tag of the container image.
WithCreationScript(IResourceBuilder<MySqlDatabaseResource>, string) Section titled WithCreationScript(IResourceBuilder<MySqlDatabaseResource>, string) extension IResourceBuilder<MySqlDatabaseResource>
Defines the SQL script used to create the database.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlDatabaseResource> WithCreationScript(
this IResourceBuilder<MySqlDatabaseResource> builder,
string script)
{
// ...
}
}
builder IResourceBuilder<MySqlDatabaseResource> The builder for the MySqlDatabaseResource.
script string The SQL script used to create the database.
IResourceBuilder<MySqlDatabaseResource> A reference to the ApplicationModel.IResourceBuilder`1.
Default script is
CREATE DATABASE IF NOT EXISTS `QUOTED_DATABASE_NAME`;
WithDataBindMount(IResourceBuilder<MySqlServerResource>, string, bool) Section titled WithDataBindMount(IResourceBuilder<MySqlServerResource>, string, bool) extension IResourceBuilder<MySqlServerResource>
Adds a bind mount for the data folder to a MySql container resource.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlServerResource> WithDataBindMount(
this IResourceBuilder<MySqlServerResource> builder,
string source,
bool isReadOnly = false)
{
// ...
}
}
builder IResourceBuilder<MySqlServerResource> The resource builder.
source string The source directory on the host to mount into the container.
isReadOnly bool optional A flag that indicates if this is a read-only mount.
IResourceBuilder<MySqlServerResource> The ApplicationModel.IResourceBuilder`1.
WithDataVolume(IResourceBuilder<MySqlServerResource>, string?, bool) Section titled WithDataVolume(IResourceBuilder<MySqlServerResource>, string?, bool) extension IResourceBuilder<MySqlServerResource>
Adds a named volume for the data folder to a MySql container resource.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlServerResource> WithDataVolume(
this IResourceBuilder<MySqlServerResource> builder,
string? name = null,
bool isReadOnly = false)
{
// ...
}
}
builder IResourceBuilder<MySqlServerResource> The resource builder.
name string? optional The name of the volume. Defaults to an auto-generated name based on the application and resource names.
isReadOnly bool optional A flag that indicates if this is a read-only volume.
IResourceBuilder<MySqlServerResource> The ApplicationModel.IResourceBuilder`1.
WithHostPort(IResourceBuilder<PhpMyAdminContainerResource>, int?) Section titled WithHostPort(IResourceBuilder<PhpMyAdminContainerResource>, int?) extension IResourceBuilder<PhpMyAdminContainerResource>
Configures the host port that the PGAdmin resource is exposed on instead of using randomly assigned port.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<PhpMyAdminContainerResource> WithHostPort(
this IResourceBuilder<PhpMyAdminContainerResource> builder,
int? port)
{
// ...
}
}
builder IResourceBuilder<PhpMyAdminContainerResource> The resource builder for PGAdmin.
port int? The port to bind on the host. If null is used, a random port will be assigned.
IResourceBuilder<PhpMyAdminContainerResource> The resource builder for PGAdmin.
WithInitBindMount(IResourceBuilder<MySqlServerResource>, string, bool) Section titled WithInitBindMount(IResourceBuilder<MySqlServerResource>, string, bool) extension IResourceBuilder<MySqlServerResource>
Adds a bind mount for the init folder to a MySql container resource.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlServerResource> WithInitBindMount(
this IResourceBuilder<MySqlServerResource> builder,
string source,
bool isReadOnly = true)
{
// ...
}
}
builder IResourceBuilder<MySqlServerResource> The resource builder.
source string The source directory on the host to mount into the container.
isReadOnly bool optional A flag that indicates if this is a read-only mount.
IResourceBuilder<MySqlServerResource> The ApplicationModel.IResourceBuilder`1.
WithInitFiles(IResourceBuilder<MySqlServerResource>, string) Section titled WithInitFiles(IResourceBuilder<MySqlServerResource>, string) extension IResourceBuilder<MySqlServerResource>
Copies init files into a MySql container resource.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlServerResource> WithInitFiles(
this IResourceBuilder<MySqlServerResource> builder,
string source)
{
// ...
}
}
builder IResourceBuilder<MySqlServerResource> The resource builder.
source string The source file or directory on the host to copy into the container.
IResourceBuilder<MySqlServerResource> The ApplicationModel.IResourceBuilder`1.
WithPassword(IResourceBuilder<MySqlServerResource>, IResourceBuilder<ParameterResource>) Section titled WithPassword(IResourceBuilder<MySqlServerResource>, IResourceBuilder<ParameterResource>) extension IResourceBuilder<MySqlServerResource>
Configures the password that the MySQL resource uses.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlServerResource> WithPassword(
this IResourceBuilder<MySqlServerResource> builder,
IResourceBuilder<ParameterResource> password)
{
// ...
}
}
builder IResourceBuilder<MySqlServerResource> The resource builder.
password IResourceBuilder<ParameterResource> The parameter used to provide the password for the MySQL resource.
IResourceBuilder<MySqlServerResource> The ApplicationModel.IResourceBuilder`1.
WithPhpMyAdmin(IResourceBuilder<T>, Action<IResourceBuilder<PhpMyAdminContainerResource>>, string?) Section titled WithPhpMyAdmin(IResourceBuilder<T>, Action<IResourceBuilder<PhpMyAdminContainerResource>>, string?) extension IResourceBuilder<T>
Adds a phpMyAdmin administration and development platform for MySql to the application model.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<T> WithPhpMyAdmin<T>(
this IResourceBuilder<T> builder,
Action<IResourceBuilder<PhpMyAdminContainerResource>>? configureContainer = null,
string? containerName = null)
{
// ...
}
}
builder IResourceBuilder<T> The MySql server resource builder.
configureContainer Action<IResourceBuilder<PhpMyAdminContainerResource>> optional Callback to configure PhpMyAdmin container resource.
containerName string? optional The name of the container (Optional).
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1.
This version of the package defaults to the tag of the container image.