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 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
4)Executing Bash Shell:
docker exec -it image-name /bin/bash5)Access mysql:
mysql -u root -p -A6)Access User & Host Column:
select user,host from mysql.user;7)Setting host to ‘%’:
update mysql.user set host=’%’ where user=’root’;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;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.
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.