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











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.
