0% found this document useful (0 votes)
6 views

MySQL Server Installation

MySQL Server Installation In a Custom Location

Uploaded by

bymash2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

MySQL Server Installation

MySQL Server Installation In a Custom Location

Uploaded by

bymash2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Prepare the System

Ensure the system has the necessary tools and libraries.

sudo yum update -y


sudo yum install wget tar gcc libaio -y

2. Download MySQL Binaries

Download the desired version of MySQL from the official MySQL website.

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.xx-linux-
glibc2.xx-x86_64.tar.xz

Replace xx with the version numbers.

3. Extract the MySQL Binaries

Extract the tarball into the custom directory /app/mysql.

sudo mkdir -p /app/mysql


sudo tar -xvf mysql-8.0.xx-linux-glibc2.xx-x86_64.tar.xz -C /app/mysql --
strip-components=1

4. Create a MySQL User and Group

Create a dedicated user and group for MySQL.

sudo groupadd mysql


sudo useradd -r -g mysql mysql

5. Set Up the MySQL Data Directory

Initialize the MySQL data directory within the base directory.

sudo mkdir -p /app/mysql/data


sudo chown -R mysql:mysql /app/mysql
cd /app/mysql
sudo bin/mysqld --initialize --user=mysql --basedir=/app/mysql
--datadir=/app/mysql/data

6. Configure MySQL

Create a custom configuration file /app/mysql/my.cnf to define the custom basedir and
datadir.
sudo vi /app/mysql/my.cnf

Add the following content:

[mysqld]
basedir=/app/mysql
datadir=/app/mysql/data
port=3306
socket=/app/mysql/mysql.sock
log-error=/app/mysql/mysql-error.log
pid-file=/app/mysql/mysql.pid

7. Set Up the MySQL Service

Create a custom systemd service file to manage MySQL.

sudo vi /etc/systemd/system/mysql.service

Add the following content:

[Unit]
Description=MySQL Server
After=network.target

[Service]
User=mysql
Group=mysql
ExecStart=/app/mysql/bin/mysqld --defaults-file=/app/mysql/my.cnf
LimitNOFILE=5000

[Install]
WantedBy=multi-user.target

Reload the systemd daemon to recognize the new service.

sudo systemctl daemon-reload

8. Start and Enable MySQL

Start the MySQL service and enable it to run on boot.

sudo systemctl start mysql


sudo systemctl enable mysql

9. Secure MySQL

Run the MySQL secure installation script to set up security settings.

/app/mysql/bin/mysql_secure_installation
10. Verify Installation

Log in to MySQL to ensure it is working properly.

/app/mysql/bin/mysql -u root -p

This process allows you to install and configure MySQL in a custom directory, making it
independent of the default /usr paths.

You might also like