Home  >  Article  >  Database  >  Compile and install mysql on centos

Compile and install mysql on centos

王林
王林Original
2023-05-23 10:18:37567browse

CentOS Compile and Install MySQL

MySQL is a popular relational database management system. Installing and configuring MySQL on a Linux server is one of the necessary steps for web development and operation. While many Linux distributions include precompiled versions of MySQL, this article will explain how to install MySQL using source code compilation.

This article will demonstrate how to install the latest version of MySQL 8.0.27 on CentOS 7. Before you begin, make sure you have the following tools installed on your CentOS server:

  • A CentOS 7 server
  • A sudo non-root user
  • gcc compiler and make command
  • wget and tar command
  1. Download the source code of MySQL

To download the source code of MySQL, please go to MySQL official website and get the latest version of the source code files from the download page. Alternatively, you can download MySQL via the wget command on the CentOS server with the following command:

$ sudo wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.27.tar.gz

This will download the MySQL 8.0.27 source code files to the current directory of the CentOS server.

  1. Decompress the MySQL source code

Use the following command to decompress the MySQL 8.0.27 source code you just downloaded:

$ sudo tar xf mysql-8.0.27.tar.gz

This command will decompress the MySQL source code Extract the file to the current directory.

  1. Install dependencies

Use the following commands to install some required dependencies on the CentOS server:

$ sudo yum install -y libaio-devel openssl-devel
  1. Compile and install MySQL

The following are the steps to compile and install MySQL:

$ cd mysql-8.0.27
$ sudo groupadd mysql
$ sudo useradd -r -g mysql -s /bin/false mysql
$ sudo cmake . -DMYSQL_DATADIR=/var/lib/mysql 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DDEFAULT_CHARSET=utf8mb4 
-DDEFAULT_COLLATION=utf8mb4_unicode_ci 
-DWITH_BOOST=/usr/local/boost 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_PARTITION_STORAGE_ENGINE=1 
-DWITH_FEDERATED_STORAGE_ENGINE=1 
-DENABLED_LOCAL_INFILE=1 
-DENABLE_DOWNLOADS=1 
-DDOWNLOAD_BOOST=1 
-DWITH_SSL=system 
-DWITH_ZLIB=bundled 
-DENABLED_LOCAL_INFILE=1 
-DENABLE_DTRACE=0 
-DWITH_DEBUG=0
$ sudo make
$ sudo make install

Here is the meaning of these parameters:

  • MYSQL_DATADIR=/var/lib/mysql: Specify the MySQL data directory.
  • CMAKE_INSTALL_PREFIX=/usr/local/mysql: Specify the installation directory of MySQL.
  • DEFAULT_CHARSET=utf8mb4 and DEFAULT_COLLATION=utf8mb4_unicode_ci: Use UTF-8 encoding.
  • WITH_BOOST=/usr/local/boost: Use the Boost library.
  • WITH_INNOBASE_STORAGE_ENGINE=1, WITH_ARCHIVE_STORAGE_ENGINE=1, WITH_BLACKHOLE_STORAGE_ENGINE=1, WITH_PARTITION_STORAGE_ENGINE=1 and WITH_FEDERATED_STORAGE_ENGINE=1: Use different storage engines.
  • ENABLE_DOWNLOADS=1 and DOWNLOAD_BOOST=1: Download the Boost library from the MySQL official website.
  • WITH_SSL=system and WITH_ZLIB=bundled: Only use the system's OpenSSL and MySQL's built-in Zlib library.
  • ENABLED_LOCAL_INFILE=1: Allows the use of the "LOAD DATA LOCAL INFILE" statement.
  • ENABLE_DTRACE=0: Disable the DTrace function.
  • WITH_DEBUG=0: Disable debugging information.
  1. Configuring MySQL

Create a MySQL configuration file and enable system logging using the following command:

$ sudo cp support-files/mysql.server /etc/init.d/mysql
$ sudo chmod +x /etc/init.d/mysql
$ sudo touch /var/log/mysql/mysqld.log
$ sudo chown -R mysql:mysql /usr/local/mysql
$ sudo chown -R mysql:mysql /var/log/mysql
$ sudo ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

Then, edit /etc/my. cnf file and add the following content:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
  1. Initialize MySQL and set the administrator password

Use the following commands to initialize MySQL and set the administrator password:

$ cd /usr/local/mysql/bin
$ sudo ./mysqld --initialize-insecure --user=mysql
$ sudo chown -R mysql:mysql /var/lib/mysql
$ sudo systemctl start mysql
$ sudo /usr/local/mysql/bin/mysql_secure_installation

--initialize-insecure: Initialize MySQL and allow unencrypted root password.

--user=mysql: Start MySQL as the mysql user.

mysql_secure_installation: Run the MySQL secure installation wizard and set a password for the root user.

  1. Testing MySQL

Finally, use the following command to test whether MySQL is successfully installed and log in with the newly set administrator password:

$ mysql -u root -p

If everything Normally, you should be able to log in to the MySQL command line prompt.

Summary

Compiling and installing MySQL on CentOS 7 may take some time and effort, but it provides fine-grained control and better performance. This is a great choice if you use MySQL for production workloads. By following the steps in this article, you should be able to successfully install and configure MySQL on your CentOS server.

The above is the detailed content of Compile and install mysql on centos. 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