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:
- A CentOS 7 server
- A sudo non-root user
- gcc compiler and make command
- wget and tar command
- Download the source code of MySQL
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.
- Decompress the MySQL source code
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.
- Install dependencies
Use the following commands to install some required dependencies on the CentOS server:
$ sudo yum install -y libaio-devel openssl-devel
- Compile and install MySQL
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:
- MYSQL_DATADIR=/var/lib/mysql: Specify the MySQL data directory.
- CMAKE_INSTALL_PREFIX=/usr/local/mysql: Specify the installation directory of MySQL.
- DEFAULT_CHARSET=utf8mb4 and DEFAULT_COLLATION=utf8mb4_unicode_ci: Use UTF-8 encoding.
- WITH_BOOST=/usr/local/boost: Use the Boost library.
- WITH_INNOBASE_STORAGE_ENGINE=1, WITH_ARCHIVE_STORAGE_ENGINE=1, WITH_BLACKHOLE_STORAGE_ENGINE=1, WITH_PARTITION_STORAGE_ENGINE=1 and WITH_FEDERATED_STORAGE_ENGINE=1: Use different storage engines.
- ENABLE_DOWNLOADS=1 and DOWNLOAD_BOOST=1: Download the Boost library from the MySQL official website.
- WITH_SSL=system and WITH_ZLIB=bundled: Only use the system's OpenSSL and MySQL's built-in Zlib library.
- ENABLED_LOCAL_INFILE=1: Allows the use of the "LOAD DATA LOCAL INFILE" statement.
- ENABLE_DTRACE=0: Disable the DTrace function.
- WITH_DEBUG=0: Disable debugging information.
- Configuring MySQL
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
- Initialize MySQL and set the administrator password
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.
- Testing MySQL
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.
