0% found this document useful (0 votes)
16 views3 pages

Install and Configure MySQL on Linux

MySQL Server Installation In a Custom Location

Uploaded by

bymash2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Install and Configure MySQL on Linux

MySQL Server Installation In a Custom Location

Uploaded by

bymash2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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 [Link]
[Link]-x86_64.[Link]

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 [Link]-x86_64.[Link] -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/[Link] to define the custom basedir and
datadir.
sudo vi /app/mysql/[Link]

Add the following content:

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

7. Set Up the MySQL Service

Create a custom systemd service file to manage MySQL.

sudo vi /etc/systemd/system/[Link]

Add the following content:

[Unit]
Description=MySQL Server
After=[Link]

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

[Install]
WantedBy=[Link]

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.

Common questions

Powered by AI

The initial steps to prepare a system for MySQL installation on a Linux environment include updating the system and installing necessary tools and libraries. Using the command 'sudo yum update -y' ensures all system packages are up-to-date, which is crucial for security and compatibility. The command 'sudo yum install wget tar gcc libaio -y' installs essential tools like wget, for downloading files from the web; tar, for extracting the downloaded MySQL files; gcc, a compiler needed for building C programs; and libaio, which is required for asynchronous I/O operations. These steps are important to ensure that the system is equipped with all necessary dependencies that MySQL relies on for installation and operation .

Verification of a successful MySQL installation involves logging into the MySQL server using the command '/app/mysql/bin/mysql -u root -p'. This step allows administrators to check core functionality, such as connection and command execution capabilities. Verification is crucial not only to confirm that installation steps were correctly followed but also to ensure readiness for operational use. It checks that network communications, user authentication, and database access permissions are correctly configured, which are essential for detecting installation issues early .

The custom 'my.cnf' file is significant because it allows administrators to define specific MySQL runtime configurations tailored to the needs of their setup. By specifying parameters such as 'basedir', 'datadir', 'port', and others, the custom configuration file ensures that MySQL runs with the desired settings, which may differ from default installations, thus providing flexibility and control over system resources and behavior. This customization is crucial for performance tuning and ensuring compatibility with existing network and storage configurations .

Reloading the systemd daemon using 'sudo systemctl daemon-reload' is important because it forces the systemd to re-read all service configurations and recognize any new services added, such as the MySQL service. This ensures that systemd can properly start, stop, and manage the newly created or updated services. If this step is skipped, the system may not acknowledge the service changes or additions, leading to failures in starting the MySQL service or systemd behaving unpredictably due to cached outdated configurations .

Creating a separate user and group for MySQL enhances system security by minimizing permissions and isolating MySQL operations under a dedicated user account. This means that any potential compromises or vulnerabilities are restricted to the MySQL user, reducing the risk of system-wide impacts. Moreover, it simplifies management, as all MySQL processes and file permissions can be easily tracked and managed under this specific user and group setup, making system administration more organized .

The 'mysql_secure_installation' script enhances MySQL security by allowing administrators to quickly configure important security settings. It helps set a root password, remove anonymous users, disallow root login remotely, remove test databases, and reload privilege tables to activate changes. These actions close common vulnerabilities by ensuring authenticated control over MySQL access and removal of unnecessary default settings that could be exploited .

Creating a systemd service for managing MySQL involves adding a custom service configuration file at '/etc/systemd/system/mysql.service'. The configuration includes defining service description, specifying the user and group, setting the execution command with '--defaults-file', and limiting resources if needed. Reloading the systemd daemon with 'sudo systemctl daemon-reload' ensures the system recognizes the new service. A custom service configuration provides benefits such as starting MySQL with specific configurations, handling dependencies with 'After=network.target', and offering resource limitation through 'LimitNOFILE', enhancing the control over how the MySQL instance interacts with the system environment .

Defining custom parameters in a 'my.cnf' file allows administrators to tailor MySQL's performance criteria to fit specific application needs. By adjusting settings such as buffer sizes, cache limits, connection limits, and other performance-related configurations, MySQL can be optimized for the workload it is expected to handle. This customization can lead to significant improvements in resource utilization, response times, and overall throughput of database queries, providing operational efficiency by aligning database performance with organizational demands and available infrastructure .

Initializing the MySQL data directory involves creating the directory structure and setting up the database system tables. This is done using the command 'sudo bin/mysqld --initialize --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data'. The process ensures that MySQL sets up necessary system databases and files needed for operation, and it sets up initial security settings. This step is crucial for creating the foundational data structure that MySQL requires to store database information and to ensure that the server operates correctly post-installation .

Not properly setting the ownership and permissions for MySQL directories can result in security vulnerabilities and operational failures. Unauthorized users might gain access to sensitive data, or the MySQL server might not have the necessary permissions to read or write to its data directories, leading to server errors. The directories should be configured by assigning ownership to the MySQL user and group with 'sudo chown -R mysql:mysql /app/mysql', ensuring only these accounts have write access, which helps secure the data and maintains the server's ability to manage database files effectively .

You might also like