Experts teach you how to build a MySQL database system

Time:2021-8-1

As an excellent web server software, Apache HTTP server provides user-oriented front-end application functions. In the actual enterprise website platform, in order to provide richer and more powerful web application functions, it often needs the support of background database, web page programming language and other roles.

1、 Compiling and installing MySQL

MySQL is a real multi-threaded and multi-user SQL database service. With its high performance, high reliability and easy-to-use characteristics, MySQL is called the most popular open source database system in the server field. Before 2008, MySQL project was developed, released and supported by MySQL AB company. After that, it went through the process of Sun company acquiring MySQL AB company and Oracle company acquiring Sun company. At present, Oracle company is responsible for the operation and maintenance of MySQL project.

In order to ensure the integrity and customizability of MySQL database functions, MySQL database system is generally installed by source code compilation. MySQL 5. X series is the most widely used version, which has good stability and compatibility. The following will take mysql-5.6.36.tar.gz as an example( Source package (available for download on the official website)

1. Preparation

1) In order to avoid port conflicts and program conflicts, it is recommended to query the installation of MySQL software and confirm that MySQL server and MySQL packages are not installed by rpm, otherwise it is recommended to uninstall them.

2) Then install the ncurses devel package that comes with the CD. Ncurses is the basic library of screen control under the character terminal. Maybe many newly developed programs are no longer used. If you want to compile some old programs, you will often encounter it. You need to log in to MySQL on the host under TTY. As shown below:

3) MySQL 5. X Series requires cmake compilation and installation, so install the cmake package first (you can download the source package from the cmake official website). As shown below:

2. Create a running user

In order to strengthen the permission control of database services, it is recommended to use special running users, such as mysql. This user does not need to log in to the system and can not create a host folder. As follows:

[[email protected] ~]# groupadd mysql

[[email protected] ~]# useradd -M -s /sbin/nologin mysql -g mysql

3. Unpack, configure, compile and install

Unzip the downloaded MySQL source package and switch to the source directory. Since MySQL 5.5, the MySQL source code installation began to use cmake. Set the source code and compile the configuration script, as shown in the following figure:

Experts teach you how to build a MySQL database system

In the above configuration command, the meanings of each option are as follows:

-DCMAKE_ INSTALL_ Prefix: specifies to install the MySQL database program into a directory- Dsysconfdir: Specifies the initialization parameter file directory- DDEFAULT_ Charset: Specifies the character set encoding used by default, such as utf-8-ddefault_ Collation: Specifies the default character set collation rule, utf8_ general_ Ci is a general rule applicable to UTF-8 character set- DWITH_ EXTRA_ Charsets: Specifies additional character set encodings supported. Configuration items will change according to the actual environment and are not fixed. Therefore, when different requirements are required, you can find them according to various aspects and be flexible.

4. Other adjustments after installation

1) Set the permissions for the database directory as follows:

[[email protected] ~]# chown -R mysql:mysql /usr/local/mysql

2) Create profile

The CentOS 7 system supports the MariaDB database by default, so the system’s default / etc / my.cnf configuration file is the MariaDB configuration file. Under the support file folder in the MySQL source directory, the default sample configuration file my-default.cnf file of MySQL database is provided. Before starting the MySQL database service, you need to replace the original my.cnf file with the configuration file provided by mysql. As shown below:

Experts teach you how to build a MySQL database system

3) Initialize database

In order to use the MySQL database system normally, execute the initialization script MySQL as the running user mysql_ install_ DB, specify the data storage directory, etc. As shown below:

4) Setting environment variables

To facilitate the use of MySQL commands in any directory, you need to set the environment variable in / etc / profile/ The file, etc / profile, is the environment variable setting that each user will run when logging in, as shown in the following figure:

You can also edit with VIM, and the results are the same.

5. Add MySQL as system service

If you want to add mysqld system services for management through systemctl, you can directly use the service scripts provided in the source package. Find the mysql.server script file in the support files folder, copy it to the / usr / local / MySQL / bin / directory and change it to mysqld.sh, then create the configuration file of MySQL system service / usr / lib / SYSTEMd / system / mysqld.server and add it as mysqld system service. As shown below:

In this way, you can use the systemctl tool to control the MySQL database service in the future. If the addition fails, you can use the “/ usr / local / MySQL / bin / mysqld.sh start / stop / restart” command to start / close / restart the database. The results are the same.

MySQL server provides services through tcp3306 port by default. You can change the listening port by editing the “port = 3306” line of the [mysqld] configuration end in the / etc / my.cnf configuration file. We will describe in detail how to use the database and authorize database users later.

The following is my error report when doing the experiment:

Initialization error, as shown in the following figure:

Solution: install the Autoconf library

Enter command

#Yum y install Autoconf / / the data: dumper module will be installed when installing this package. The system disk can be used as the yum source. The system disk has

Install the Autoconf library and run it again

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

Ruby uses eventmachine to add file download capabilities to the HTTP server

Idea:Use ruby eventmachine and EM HTTP server gem to complete a simple httpserver that provides file download function;EM FileStreamer is used to send files asynchronously. When sending files, header is first assembled and FileStreamer is called. code: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 […]