Home >Database >Mysql Tutorial >How to use tar package to install MySQL under Linux system

How to use tar package to install MySQL under Linux system

PHPz
PHPzOriginal
2023-04-17 16:40:332255browse

MySQL is an open source relational database management system that is fast, reliable and flexible. There are many ways to install MySQL. This article mainly introduces how to install MySQL using tar packages under Linux systems.

1. Download MySQL

Download the required MySQL version from the official website https://dev.mysql.com/downloads/mysql/. After selecting "Linux-Generic", select the .tar file of the corresponding version to download. For example: mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz

2. Decompress MySQL

Use the tar command to decompress the file in the Linux system, tar.xz is compressed The suffix name of the file, x represents the decompression operation, J represents the use of xz decompressor, and f represents the file name of the specified decompression operation.

$ tar -xJf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz

After decompression, you will get a directory of mysql-8.0.23-linux-glibc2.12-x86_64.

3. Configure MySQL

1. Create data directory and log directory

$ mkdir /usr/local/mysql
$ mkdir /data/mysql
$ mkdir /data/mysql/log

2. Create MySQL user and user group

$ groupadd mysql
$ useradd -r -g mysql -s /bin/false mysql

3. Copy the decompressed MySQL directory to the /usr/local/mysql directory

$ cp -r mysql-8.0.23-linux-glibc2.12-x86_64/* /usr/local/mysql

4. Enter the MySQL directory and grant permissions

$ cd /usr/local/mysql
$ chown -R mysql:mysql .
$ chown -R mysql:mysql /data/mysql

5. Initialize the data directory

$ bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --log-error=/data/mysql/log/error.log --pid-file=/data/mysql/mysql.pid

or above The --user parameter in the command indicates the user who started the MySQL service, --basedir indicates the MySQL installation directory, --datadir indicates the data directory, --log-error indicates the location of the error log relative to the data directory, --pid-file Represents the location of the process ID file.

4. Start MySQL

$ bin/mysqld_safe --user=mysql &

5. Log in to MySQL

$ bin/mysql -u root -p

A screen prompting you to enter a password will appear. Enter the random password output during the initialization of the data directory, and then press Enter. key. If correct, you can enter the MySQL console.

At this point, the MySQL linux tar package installation is complete.

Summary

Through the introduction of this article, we have learned how to install MySQL using tar packages under Linux systems, which mainly includes downloading MySQL, decompressing MySQL, configuring MySQL, starting MySQL, and logging in. MySQL and other steps. I hope this article will be helpful to you and help you better install and use MySQL.

The above is the detailed content of How to use tar package to install MySQL under Linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn