To install MySQL on CentOS system, you can choose to use the source code installation method. Compared with directly using binary package installation, this method can customize the configuration of MySQL more flexibly, and at the same time, it can also provide an in-depth understanding of the working principle of MySQL from the source code level.
This article will introduce the detailed steps to install MySQL using source code on CentOS system.
Step One: Preparation
Before you start installing MySQL, you need to install some necessary software packages and dependencies. You can use the following command to install:
yum groupinstall "Development Tools" yum install cmake ncurses-devel
Step 2: Download the source code
Download the source code package on the MySQL official website, select the version suitable for your server system and the corresponding compressed package:
https://dev.mysql.com/downloads/mysql/
Copy the downloaded source code package to the server where MySQL needs to be installed.
Step 3: Unzip the source code package
Use the following command to decompress the source code package:
tar -zxvf mysql-xxx.tar.gz
Step 4: Create MySQL users and groups
Create one Dedicate users and groups to running MySQL, which improves security. Use the following command to create:
groupadd mysql useradd -r -g mysql -s /bin/false mysql
Step 5: Compile and install MySQL
cd mysql-xxx
mkdir bld cd bld
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
Parameter description:
-DCMAKE_INSTALL_PREFIX
: Specify the installation path of MySQL, the default is /usr/local/mysql. -DMYSQL_DATADIR
: Specify the MySQL data directory, the default is /usr/local/mysql/data. -DSYSCONFDIR
: Specify the MySQL configuration file directory, the default is /etc. -DWITH_MYISAM_STORAGE_ENGINE
: Enable the MyISAM storage engine. -DWITH_INNOBASE_STORAGE_ENGINE
: Enable the InnoDB storage engine. -DWITH_MEMORY_STORAGE_ENGINE
: Enable the Memory storage engine. -DWITH_READLINE
: Enable readline library. -DENABLED_LOCAL_INFILE
: Allows data to be imported from local files. -DMYSQL_UNIX_ADDR
: Specify the MySQL Unix socket file path, the default is /var/run/mysql/mysql.sock. -DMYSQL_TCP_PORT
: Specify the MySQL TCP listening port, the default is 3306. make make install
Change the MySQL source code directory Copy the supporting files under to the MySQL installation directory:
cd /usr/local/mysql cp support-files/my-default.cnf /etc/my.cnf
Modify the MySQL configuration file my.cnf and add the following parameters:
[mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data socket = /var/run/mysql/mysql.sock
Step 6: Start MySQL
Start MySQL Service:
service mysqld start
Set MySQL to start automatically at boot:
chkconfig mysqld on
Step 7: Set the MySQL password
After the MySQL installation is completed, you need to set the password of the root user:
mysql_secure_installation
Follow the following steps according to the prompts:
The complete installation process is completed and MySQL can be used normally.
Summary
Using source code to install MySQL can more flexibly customize the configuration of MySQL than directly using binary packages. At the same time, you can also have an in-depth understanding of the working principle of MySQL from the source code level.
Through the introduction of this article, I believe that readers have mastered the basic process of installing MySQL source code on CentOS systems and can set it up according to their own needs. If you have any questions, please leave a message in the comment area.
The above is the detailed content of centos installation mysql source code. For more information, please follow other related articles on the PHP Chinese website!