What I usually do is login to my server with mysqlsh and then
dba.checkInstanceConfiguration()
dba.createCluster("mycluster")
But now I need to create a single node cluster inside a testcontainer as part of an End2End-Test.
How do I accomplish this with testcontainers-go?
Currently I am trying build the container like this:
testExec := testcontainers.NewRawCommand([]string{`echo "dba.configureInstance();dba.createCluster("mycluster") | mysqlsh -ppassword -uroot`})
mysqlContainer, err := mysql.RunContainer(ctx,
testcontainers.WithImage(mysqlImageVersion),
mysql.WithUsername("root"),
mysql.WithPassword("password"),
mysql.WithDatabase("mysql"),
testcontainers.WithAfterReadyCommand(testExec),
mysql.WithConfigFile(filepath.Join("test", "test.cnf")),
)
The contents of the config file from “WithConfigFile”:
[mysqld]
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
server_id = 12345678
binlog_transaction_dependency_tracking = WRITESET
gtid_mode = ON
enforce_gtid_consistency = ON
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock
But this doesn’t seem to work.
When I run a command to check for the primary (I got this cmd from here)
SELECT member_host FROM performance_schema.global_status JOIN performance_schema.replication_group_members WHERE variable_name = 'group_replication_primary_member' AND member_id=variable_value
I am getting an empty result. I would expect the name of the primary instance.
AlexTheOpsGuy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.