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!

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor
