Introduction:
Liferay utilizes a default database to store all its data. However, when the need arises to integrate a custom database, there are multiple ways to achieve this with Liferay. One popular method for incorporating a MySQL database is through Docker.
Prerequisites
> JDK 11
> Liferay 7.4
> Docker
Setup Mysql Image For Docker
1)Checking Docker:
Checking the docker version by entering “docker –version”
![Docker version check command | Liferay With Docker Docker version check command](https://www.ignek.com/wp-content/uploads/2024/03/Docker-version-check-command.webp)
![Downloading MySQL container image | Liferay With Docker Downloading MySQL container image](https://www.ignek.com/wp-content/uploads/2024/03/Downloading-MySQL-container-image-1024x290.webp)
docker run -p 6603:3306 –name my-mysql -e MYSQL_ROOT_PASSWORD=root -d mysql/mysql-server:5.7
Let’s break down the command:
docker run: This is the basic command to run a Docker container.
-p 6603:3306: This option maps port 6603 on the host machine to port 3306 on the container.
Port 3306 is the default port for MySQL, and by using this option, you are making the MySQL service inside the container accessible on the host machine at port 6603.
–name my-mysql: This option assigns the name “my-mysql” to the running container. Naming containers can make it easier to manage and reference them.
-e MYSQL_ROOT_PASSWORD=root: This sets the environment variable MYSQL_ROOT_PASSWORD to “root”. This is specifying the root password for the MySQL server inside the container. In this case, it’s set to “root”.
-d: This option runs the container in the background (detached mode).
mysql/mysql-server:5.7: This is the name and tag of the Docker image to be used for creating the container. In this case, it’s pulling the MySQL Server image version 5.7 from the official Docker Hub repository (repository: mysql, image: mysql-server, tag: 5.7).
3)Checking Image:
docker ps -a
![Listing Docker containers | Liferay With Docker Listing Docker containers](https://www.ignek.com/wp-content/uploads/2024/03/Listing-Docker-containers-1024x73.webp)
4)Executing Bash Shell:
docker exec -it image-name /bin/bash
![Docker Bash Shell Execution Command | Liferay With Docker Docker Bash Shell Execution Command](https://www.ignek.com/wp-content/uploads/2024/03/Docker-Bash-Shell-Execution-Command.webp)
5)Access mysql:
mysql -u root -p -A
![Access MySQL via command line | Liferay With Docker Access MySQL via command line](https://www.ignek.com/wp-content/uploads/2024/03/Access-MySQL-via-command-line-1024x426.webp)
6)Access User & Host Column:
select user,host from mysql.user;
![Access MySQL user and host | Liferay With Docker Access MySQL user and host](https://www.ignek.com/wp-content/uploads/2024/03/Access-MySQL-user-and-host.webp)
7)Setting host to ‘%’:
update mysql.user set host=’%’ where user=’root’;
![Set host in MySQL | Liferay With Docker Set host in MySQL](https://www.ignek.com/wp-content/uploads/2024/03/Set-host-in-MySQL.webp)
when we execute this query, it will update the mysql.user table, setting the host column to ‘%’ for the user with the username ‘root’. This effectively allows the user ‘root’ to connect from any host.
8)Reloading Privileges:
flush privileges;
![Refreshing Privileges | Liferay With Docker Refreshing Privileges](https://www.ignek.com/wp-content/uploads/2024/03/Refreshing-Privileges.webp)
FLUSH: This command is used to reset or refresh various system parameters in MySQL.
In this case, FLUSH PRIVILEGES is specifically used to reload the privileges from the grant tables.
Setup Liferay Database
To set up the Lifeary database firstly we need to go to the Liferay home folder.
Now create the portal-ext.properties in it.
After creating the properties file, do these entries in the file.
![Setup Liferay database using portal ext file | Liferay With Docker Setup Liferay database using portal ext file](https://www.ignek.com/wp-content/uploads/2024/03/Setup-Liferay-database-using-portal-ext-file-1024x113.webp)
Change the underlined entries with our port name, database name, MySQL username, and password, respectively.
Our setup is finished, We are ready to start the Liferay.
![Liferaysetup is finished | Liferay With Docker Liferay setup is finished](https://www.ignek.com/wp-content/uploads/2024/03/Liferaysetup-is-finished-1024x395.webp)