testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::modules::MySQLContainer Class Reference

A running MySQL server: connection getters plus the owned container. More...

#include <testcontainers/modules/MySQL.hpp>

Public Member Functions

const std::string & host () const noexcept
 The address a client in the test process connects to.
std::uint16_t port () const noexcept
 The host port published for the server port 3306.
const std::string & username () const noexcept
const std::string & password () const noexcept
const std::string & root_password () const noexcept
 Root's password — always the same value as password() by construction (empty only for a passwordless-root config).
const std::string & database () const noexcept
std::string connection_string () const
 The server URL, mysql://user[:password]@host:port[/database] (no path segment when the database name is empty).
Containercontainer () noexcept
 The underlying container — exec, logs, copy files, stop() early, keep() it past the test.
const Containercontainer () const noexcept

Friends

class MySQLImage

Detailed Description

A running MySQL server: connection getters plus the owned container.

Move-only — it owns the core Container, whose destructor force-removes the server (RAII teardown; container().keep() or reuse opt out, see Container).

Member Function Documentation

◆ host()

const std::string & testcontainers::modules::MySQLContainer::host ( ) const
inlinenoexcept

The address a client in the test process connects to.

Resolved once, when the container started.

◆ port()

std::uint16_t testcontainers::modules::MySQLContainer::port ( ) const
inlinenoexcept

The host port published for the server port 3306.

Resolved once, when the container started; a container restarted by hand gets fresh ephemeral ports — re-resolve via container() then.

◆ username()

const std::string & testcontainers::modules::MySQLContainer::username ( ) const
inlinenoexcept

◆ password()

const std::string & testcontainers::modules::MySQLContainer::password ( ) const
inlinenoexcept

◆ root_password()

const std::string & testcontainers::modules::MySQLContainer::root_password ( ) const
inlinenoexcept

Root's password — always the same value as password() by construction (empty only for a passwordless-root config).

Exists so call sites that connect as root read correctly.

◆ database()

const std::string & testcontainers::modules::MySQLContainer::database ( ) const
inlinenoexcept

◆ connection_string()

std::string testcontainers::modules::MySQLContainer::connection_string ( ) const

The server URL, mysql://user[:password]@host:port[/database] (no path segment when the database name is empty).

User, password, and database are percent-encoded, so credentials with '@' or ':' survive. Clients taking discrete parameters (mysql_real_connect and friends) should prefer the component getters.

◆ container() [1/2]

Container & testcontainers::modules::MySQLContainer::container ( )
inlinenoexcept

The underlying container — exec, logs, copy files, stop() early, keep() it past the test.

The in-container client binary is mysql, e.g. container().exec({"mysql", "-h127.0.0.1", "-utest", "-ptest", "-Dtest", "-e", "SELECT 1"}).

◆ container() [2/2]

const Container & testcontainers::modules::MySQLContainer::container ( ) const
inlinenoexcept

◆ MySQLImage

friend class MySQLImage
friend