Install mysql under linux

PHPz
Release: 2023-05-08 15:15:07
Original
1333 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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

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

make && make install
Copy after login

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
Copy after login

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
Copy after login

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

mkdir -p /usr/local/mysql/data
Copy after login

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/
Copy after login

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

cd /usr/local/mysql bin/mysqld --initialize --user=mysql
Copy after login

Finally, you need to start the MySQL service:

bin/mysqld_safe --user=mysql &
Copy after login

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
Copy after login

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
Copy after login

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

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!