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.
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.
yum install gcc gcc-c++ cmake ncurses-devel
The above command will install gcc, g, cmake and ncurses-devel and other necessary compilation tools.
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.
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.
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.
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.
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!