Home  >  Article  >  Database  >  Linux source code installation mysql

Linux source code installation mysql

PHPz
PHPzOriginal
2023-05-23 13:05:07502browse

In the Linux operating system, MySQL is a widely used open source database management system. Many people choose to install MySQL on Linux for better performance and scalability. There are two installation methods for MySQL. One is to download the binary compressed package from the official website and install it, and the other is to install it from the source code. In this article, we will explain how to install MySQL from source.

  1. Download MySQL source code package
    MySQL official website provides the download of MySQL source code package. We can download the latest version of MySQL source code package directly from the official website, or use the following command to download from the terminal:
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35.tar.gz

The above command will download the source code package of MySQL 5.7.35 version. You can also download other versions of MySQL source code package.

  1. Install compilation tools
    Before compiling MySQL, you need to ensure that the following compilation tools have been installed on the Linux system:
yum install gcc gcc-c++ cmake ncurses-devel

The above command will install gcc, g, cmake and ncurses-devel and other necessary compilation tools.

  1. Unzip the MySQL source code package
    Use the following command to decompress the MySQL source code package:
tar zxvf mysql-5.7.35.tar.gz

After decompression, move the MySQL source code package to the directory where you want to install MySQL :

mv mysql-5.7.35 /usr/local/mysql-5.7

Here MySQL is installed in the /usr/local/mysql-5.7 directory.

  1. Configuring MySQL installation options
    Before installation, we need to configure some options for MySQL to ensure that MySQL is suitable for our system and needs. First, we need to create a user and group named mysql:
groupadd mysql
useradd -r -g mysql mysql

Next, we will create a my.cnf file to store the MySQL configuration options. Use the following command to create the my.cnf file:

cd /usr/local/mysql-5.7/
cp support-files/my-default.cnf /etc/my.cnf

At this point we can edit the /etc/my.cnf file and add or modify options as needed.

  1. Compile and install MySQL
    After configuring the options, we can use the following command to compile and install MySQL:
cd /usr/local/mysql-5.7/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7 
-DMYSQL_DATADIR=/usr/local/mysql-5.7/data 
-DSYSCONFDIR=/etc 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_MYISAM_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DENABLED_LOCAL_INFILE=1 
-DENABLE_DTRACE=0 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci
make && make install

The above command will compile the MySQL source code and install it In the /usr/local/mysql-5.7 directory. During compilation and installation, some errors may occur. Please resolve them individually according to the error message.

  1. Initialize the MySQL database and user
    After MySQL is successfully compiled and installed, we need to initialize the MySQL database and user to ensure that it works properly. Initialize MySQL using the following command:
cd /usr/local/mysql-5.7
./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql-5.7 --datadir=/usr/local/mysql-5.7/data

--initialize-insecure parameter indicates to initialize MySQL in an insecure way. This method is only suitable for testing and development purposes. The --user parameter specifies the MySQL startup user, and the --basedir and --datadir parameters specify the MySQL root directory and data directory.

After successfully initializing MySQL, we need to start MySQL and set the root password:

./bin/mysqld_safe --user=mysql &
./bin/mysql -u root -p

At this point, after logging in to MySQL, you can set the root password and create other users and databases.

  1. Start the MySQL service
    After completing the installation and initialization, we can use the following command to start the MySQL service:
service mysqld start

At this time, the MySQL service has been started and is ready to receive connect.

Summary
Using source code for MySQL installation can bring us more flexibility and customization. Through the introduction of this article, I believe you can easily use the source code to install MySQL. Finally, I hope this article is helpful to you.

The above is the detailed content of Linux source code installation mysql. 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 cannot be deletedNext article:mysql cannot be deleted