'Mysql 8 Slower than 5.7 on Docker
I am new to docker and I have recently been trying to setup my project on docker. I have successfully deployed the application on nginx and php and i have been successful in migrating th eDB also into a container. I have plans of moving from MySQL 5.7 to 8, but I noticed the select queries are much slower in MySQL 8.
Mysql 5.7
DockerFile
FROM mysql:5.7.29
CMD ["mysqld"]
EXPOSE 3306
docker compose:
version: '3.5'
services:
database:
build:
context: ./database
restart: always
environment:
- MYSQL_DATABASE=dbname
- MYSQL_USER=username
- MYSQL_PASSWORD=password
- MYSQL_ROOT_PASSWORD=rootpwd
ports:
- "3306:3306"
volumes:
- /Path/to/data/folder:/var/lib/mysql
volumes:
my-datavolume_five:
Mysql8
DockerFile
FROM mysql:8.0.18
CMD ["mysqld"]
EXPOSE 3306
docker-compose
version: '3.5'
services:
database:
build:
context: ./database
restart: always
environment:
- MYSQL_DATABASE=testdb
- MYSQL_USER=user
- MYSQL_PASSWORD=pwd
- MYSQL_ROOT_PASSWORD=rootpwd
command: ['--default-authentication-plugin=mysql_native_password']
ports:
- "3306:3306"
volumes:
- /Path/to/database/folder:/var/lib/mysql
volumes:
my-datavolume:
I have a sample query that that does a SELECT and I have tried it in several scenarios and it always turns out to be slow. I had the query run 100 times in a loop and there was difference of 20 seconds.
Another attempt, I had the query run 100 times on unique id's and there was still anywhere between 15 -20 seconds difference(mysql 8 being slower).
I know that database query cache is not supported anymore but I am not sure if that makes a difference in the second scenario where the id's are unique.
sample query running in loop with 100 id's
"select * from booking_table where account_id = '" . $id . "' and status = 'booked' and checked_in = 1 and checked_out = 0 and type in ('type_a','type_b') and cancelled = 0 and end_date > '<end_date_time>'";
I need to know if there are certain default settings that I might be missing and if this is something to do with mysql config or docker config.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|