MySQL is a popular open source relational database management system. It is widely used as backend storage for web applications and services because it provides reliable performance and security, and supports the handling of multiple concurrent connections.
Installing MySQL in the Linux operating system requires specifying the installation directory. The installation directory is the root directory of the MySQL installation file, which contains all functions and components of MySQL, including executable files, configuration files, data files, etc. The following will introduce the steps to install MySQL on a Linux system and how to choose the correct installation directory.
1. Select the installation directory
To select the MySQL installation directory, you need to consider the following factors:
1. System space: The installation directory needs to occupy a certain amount of disk space. Select the appropriate directory based on the remaining space on the system.
2. Permissions: You need to select a directory with write permissions to write data files and logs there.
3. Security: It is necessary to ensure that the selected directory will not be used by hackers, causing problems such as data leakage or system crash.
When choosing the installation directory, it is recommended to install MySQL in the /opt directory under the root directory, because this directory stores all third-party software. In addition, it is necessary to ensure that the directory has write permission and is safe and reliable to avoid risks such as data leakage or hacker attacks.
2. Install MySQL
In the Linux operating system, there are two ways to install MySQL: installation through Yum, and self-compilation and installation through source code.
1. Install via Yum:
Enter the following command in the terminal:
sudo yum install mysql-server mysql-client
This will install automatically MySQL related components and dependency packages need to be started after the installation is complete.
sudo systemctl start mysqld
2. Self-compile and install the source code:
Before downloading the source code of MySQL, you need to install some necessary dependencies. Enter the following command in the terminal:
sudo yum groupinstall "Development Tools"
sudo yum install ncurses-devel
Next, download the source code of MySQL, unzip and enter the source code Table of contents.
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26.tar.gz
tar -zxvf mysql-8.0.26.tar.gz
cd mysql-8.0.26/
In the source code directory, it needs to be compiled and installed. Enter the following commands on the command line:
sudo cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql
sudo make
sudo make install
Note that you need to specify the installation directory here It is /opt/mysql, which is a relatively common MySQL installation directory.
After compilation and installation are completed, configuration needs to be performed. Create a my.cnf file in the /opt/mysql directory and enter the following content:
[mysqld]
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/var/lib/mysql/mysql.sock
Among them, basedir represents the installation directory of MySQL, datadir represents the data file storage directory of MySQL, and socket represents the storage location of MySQL communication files.
After the configuration is completed, you can start the MySQL service.
sudo systemctl start mysqld
3. Summary
MySQL is an easy-to-use and widely used relational database management system. When installing MySQL on a Linux system, the first step is to select an appropriate installation directory, which requires taking into account factors such as disk space, permissions, and security. After selecting the installation directory, you can install it through Yum or compile and install it yourself from source code to make MySQL run on Linux.
The above is the detailed content of mysql installation directory linux. For more information, please follow other related articles on the PHP Chinese website!