How to use mysqltuner with EE4

mysqltuner is a perl script that helps you to tune your mysql server’s configuration. This post will cover how to run it on EasyEngine v4.

The following command will install and run mysqltuner on the global database container.

cd /opt/easyengine/services && docker-compose exec global-db bash -c '
apt update
apt install wget mysqltuner -y
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/basic_passwords.txt -O basic_passwords.txt
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/vulnerabilities.csv -O vulnerabilities.csv
mysqltuner --user root --pass ${MYSQL_ROOT_PASSWORD} --cvefile=vulnerabilities.csv --passwordfile=basic_passwords.txt'

If you have already installed it and just want to run it, then run following command:

cd /opt/easyengine/services && docker-compose exec global-db bash -c 'mysqltuner --user root --pass ${MYSQL_ROOT_PASSWORD} --cvefile=vulnerabilities.csv'

If you have created sites with local db container, you need to run the command on it manually. To find all db containers on a machine, run:

docker ps -f 'label=org.label-schema.vendor=EasyEngine' -f 'label=org.label-schema.name=db'

You can automate running above commands on all containers with following one liner:

docker ps -f 'label=org.label-schema.vendor=EasyEngine' -f 'label=org.label-schema.name=db' | xargs -I{} docker exec {} <command>

These commands will give run mysqltuner on your containers. Based on the output of mysqltuner, you’ll have to tune configuration of mysql. Location of global mysql’s config is mentioned in services filesystem documentation and location of site’s local db is mentioned in site’s filesystem documentation.

If you don’t have much experience with mysqltuner and would like a primer on it, you can read this article.