Skip to content
DocsTry Aspire
DocsTry

MySqlBuilderExtensions Methods

ClassMethods10 members
Provides extension methods for adding MySQL resources to an Hosting.IDistributedApplicationBuilder.
AddDatabase(IResourceBuilder<MySqlServerResource>, string, string?)Section titled AddDatabase(IResourceBuilder<MySqlServerResource>, string, string?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<MySqlServerResource>The MySQL server resource builder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
databaseNamestring?optionalThe 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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
passwordIResourceBuilder<ParameterResource>optionalThe parameter used to provide the root password for the MySQL resource. If null a random password will be generated.
portint?optionalThe 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)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<MySqlDatabaseResource>The builder for the MySqlDatabaseResource.
scriptstringThe 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)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<MySqlServerResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
isReadOnlybooloptionalA 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)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<MySqlServerResource>The resource builder.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
isReadOnlybooloptionalA 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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<PhpMyAdminContainerResource>The resource builder for PGAdmin.
portint?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)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<MySqlServerResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
isReadOnlybooloptionalA 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)extensionIResourceBuilder<MySqlServerResource>
Copies init files into a MySql container resource.
public static class MySqlBuilderExtensions
{
public static IResourceBuilder<MySqlServerResource> WithInitFiles(
this IResourceBuilder<MySqlServerResource> builder,
string source)
{
// ...
}
}
builderIResourceBuilder<MySqlServerResource>The resource builder.
sourcestringThe 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>)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<MySqlServerResource>The resource builder.
passwordIResourceBuilder<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?)extensionIResourceBuilder<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)
{
// ...
}
}
builderIResourceBuilder<T>The MySql server resource builder.
configureContainerAction<IResourceBuilder<PhpMyAdminContainerResource>>optionalCallback to configure PhpMyAdmin container resource.
containerNamestring?optionalThe 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.