In case to run multiple versions of MySQL, we can do in several ways. In this article, I'm going to run MySQL multiple versions using Docker & using MariaDB instead of mysql.
1. Install Docker
since we're going to use docker, of course we need to install docker. Please to follow official documentation by Docker to install on your machine.
2. Run The mysql Version
You can choose between MySQL, MariaDB, or other version. in this case I'm going to use MariaDB, so I need to run this:
docker run -d --restart=always --name mariadb-10.4.20 --env MARIADB_ROOT_PASSWORD=root -p 1042:3306 mariadb:10.4.20
--detach, -dRun container in background and print container ID
--restartRestart policy to apply when a container exits
--nameAssign a name to the container
--env, -eSet environment variables
--expose, -pExpose a port or a range of ports
3.1. How to ByPass password?
try to ssh on the running database by running:
docker exec -it mariadb-10.4.20 bash
then try to move to
HOME directory by running
and then add new file called
.my.cnf, and the content are:
[client] user=root password=root host=localhost [mysqldump] host=localhost user=root password=root
3.2. How to Run Execute?
docker exec -it mariadb-10.2.44 mysql
Once you configured 3.1. you don't need to type the password.
3.3. How to Import Database
docker exec -i mariadb-10.2.44 mysql -u user -p database_name < database.sql
Or if you want to have the progress bar whilst importing database, you can use this command: (don't forget to install pv if you don't have this package)
pv databse.sql | docker exec -i mariadb-10.2.44 sh -c 'mysql database_name'
3.4. How to export Database
docker exec -i mariadb-10.4.20 mysqldump database_name > database.sql
If you want to directly compress the file for the output, you can run this: (don't forget to install gzip if you don't have it.)
docker exec -i mariadb-10.4.20 mysqldump database_name | sed -e 's/\sDEFINER=`[^`]*`@`[^`]*`//g' | gzip -c > database.sql.gz
3.5. Remove DEFINER?
sed -e 's/\sDEFINER=`[^`]*`@`[^`]*`//g' -i database.sql
Did you find this article valuable?
Support Fiko Borizqy by becoming a sponsor. Any amount is appreciated!