Home  >  Article  >  Database  >  Install mysql under linux

Install mysql under linux

PHPz
PHPzOriginal
2023-05-08 15:15:071360browse

MySQL is an open source relational database management system that can run on various operating systems, such as Linux, Windows and macOS.

Installing MySQL on a Linux system can not only improve the security and data management capabilities of the system, but also use MySQL for data storage and retrieval in various applications. This article will introduce the steps to install MySQL on a Linux system.

Step One: Preparation

Before installing MySQL, please make sure that your Linux system has the dependencies installed. These dependencies include: gcc compiler, g compiler, make command, cmake command and zlib library.

If you do not have these dependencies in your system, you can install them in the terminal by using the following command:

sudo apt-get install gcc g++ make cmake zlib1g-dev

When you enter this command and press the Enter key, the system Downloading and installing these dependencies will begin.

Step 2: Download MySQL

Before you start installing MySQL, you need to download the MySQL software package from the MySQL official website. You can visit the following link to download the MySQL package:

https://dev.mysql.com/downloads/mysql/

You need to download MySQL Community Edition or Enterprise Edition, depending on your You need to select the corresponding version. In the download page, you can see different versions of MySQL packages and formats. You can choose a package in tar.gz format, which is a compressed package of files that you need to unzip before you can install it.

Step 3: Install MySQL

After you download the MySQL software package, you need to unzip the file and enter the unzipped directory. You can use the following command to unpack the MySQL package:

tar -zxvf mysql-8.0.26.tar.gz

This command will create a directory named mysql-8.0.26 in the current directory. Note that the version number may differ depending on the package you download.

Next, go into the unzipped directory and create a build directory. You can accomplish this step using the following command:

cd mysql-8.0.26
mkdir build
cd build

In the build directory, you need to run the cmake command to prepare for the installation of MySQL.

cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=boost

This command will use cmake to configure MySQL. Among them, -DCMAKE_INSTALL_PREFIX=/usr/local/mysql means that MySQL will be installed in the /usr/local/mysql directory, -DMYSQL_DATADIR=/usr/local/mysql /data means MySQL will use the /usr/local/mysql/data directory to store data, -DWITH_BOOST=boost means use the boost library.

When cmake has finished running, you need to build and install MySQL using the following commands:

make && make install

This process may take a while, depending on the performance of your system. When this process is completed, you need to add the MySQL executable file to the PATH environment variable:

export PATH=$PATH:/usr/local/mysql/bin

You can add this command to the .bashrc file so that MySQL is automatically added every time the system starts path of.

Step 4: Configure MySQL

After the MySQL installation is completed, you need to perform some configurations to start the MySQL service.

First, you need to use the following command to create the MySQL running user:

useradd -r -s /sbin/nologin mysql

Next, you need to use the following command to create the MySQL data storage directory:

mkdir -p /usr/local/mysql/data

Use the following command to The MySQL data storage directory is set to be owned by the mysql user:

chown -R mysql:mysql /usr/local/mysql/

You need to use the following command to initialize the MySQL data storage:

cd /usr/local/mysql
bin/mysqld --initialize --user=mysql

Finally, you need to start the MySQL service:

bin/mysqld_safe --user=mysql &

This command will start the MySQL service and run it in the background.

You can also use the following command to add the MySQL service to the system startup items:

cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql

After you complete the above steps, the MySQL service will run in the background, and you can use the following command to view the service Status:

netstat -na | grep 3306

If you see the following output, the MySQL service started successfully:

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

If you encounter any problems during the installation of MySQL, you can check the official documentation of MySQL or visit MySQL Community Forum for help.

Summary

This article introduces the detailed steps to install MySQL on a Linux system. Before installing MySQL, you need to ensure that your system has the necessary dependencies installed. Next, you need to download the MySQL package and run the cmake and make commands in the unzipped directory to complete the compilation and installation of MySQL. Finally, you need to configure MySQL and start the MySQL service.

The above is the detailed content of Install mysql under linux. 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
Previous article:mysql different dataNext article:mysql different data