Home >Database >Mysql Tutorial >Compile and install mysql on centos
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:
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.
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.
Use the following commands to install some required dependencies on the CentOS server:
$ sudo yum install -y libaio-devel openssl-devel
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:
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
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.
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!