CentOS is a very popular Linux operating system that is widely used on the server side. MySQL is one of the most widely used databases and an important part of CentOS system management. This article will introduce how to install MySQL on CentOS using source code compilation.
Before starting to compile and install MySQL, you need to install some dependencies. These dependencies are used to support MySQL or some tools during the compilation process.
Run the following command to install dependencies:
yum install -y gcc-c++ cmake ncurses-devel
You can download it from the MySQL official website (https://dev.mysql.com/ downloads/mysql/) to download the latest version of MySQL. In this article, we choose MySQL version 8.0.
After downloading, extract the file to the specified directory:
tar -zxvf mysql-8.0.23.tar.gz -C /usr/local/src/
In the decompressed MySQL source code directory, use the following command Compile:
cd /usr/local/src/mysql-8.0.23 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-8.0.23 \ -DMYSQL_DATADIR=/usr/local/mysql-8.0.23/data \ -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci \ -DWITH_BOOST=boost
It is worth noting that the "-DCMAKE_INSTALL_PREFIX" parameter is the directory path where MySQL will be installed, and the "-DMYSQL_DATADIR" parameter defines the storage location of the MySQL data files. The default is "/usr/local /mysql-8.0.23/data" folder. These two parameters can be modified according to the actual situation.
After executing the cmake command, use the following command to install MySQL:
make && make install
This process may take some time, depending on It depends on factors such as your system configuration and the directory where the MySQL source code is located.
After installing MySQL, you need to add it to the system environment variables so that other programs or users can quickly access MySQL.
Edit the /etc/profile or /ect/bash.rc file and add the following content at the end:
export PATH=$PATH:/usr/local/mysql-8.0.23/bin
After saving, execute the following command to take effect:
source /etc/profile
In versions above MySQL8.0, MySQL uses the "auth_socket" plug-in to verify user identity. If you need to log in using your MySQL account and password, you need to do some additional configuration.
First start the MySQL service:
systemctl start mysqld
Run the following command to initialize:
mysql_secure_installation
This command will create a root account and corresponding password, and will also disable anonymity in MySQL User and remote root access etc.
If you changed the location of the MySQL data file in step 3, you need to change the permissions of the folder to ensure MySQL can access this folder.
Use the following command to change the permissions of the data folder:
chown -R mysql:mysql /usr/local/mysql-8.0.23/data
After completing the above steps, you can start the MySQL service and test the connection :
systemctl start mysqld mysql -uroot -p
After entering the password, if you can successfully connect to MySQL, it means that the installation and configuration have been completed.
In short, compiling and installing MySQL on CentOS requires some basic knowledge and skills. If you encounter any problems, you can refer to the official MySQL documentation or ask for help. By installing MySQL, the performance and functions of the CentOS system will be greatly enhanced, providing a solid foundation for subsequent application construction.
The above is the detailed content of How to compile and install centos mysql. For more information, please follow other related articles on the PHP Chinese website!