make compile and install mysql database

Posted by blueman378 on Thu, 09 Dec 2021 11:44:35 +0100

catalogue

1, Compile mysql-5.7

1. Unzip file

2. Installation dependent environment

3. Create a user

4. cmake parsing

5. make compile install

2, Modify profile

1. Change primary group

2. Enter configuration file

3. Modify the primary group of the profile

4. Setting environment variables

5. Initialize database

6. Add launcher

7. Open service

8. Enter database

Mysql database has the advantages of small volume, fast speed, low overall cost of ownership and open source code. It is widely used. Generally, MySQL is selected as the website database for the development of small and medium-sized websites. Because of the excellent performance of its community version, it is matched with PHP And Apache server can form a good development environment.

To install on linux operating system, you need to use make to compile and install

Here are the installation steps

1, Compile mysql-5.7

1. Unzip file

Link: https://pan.baidu.com/s/1lb_VvNn4IHlna_4q_KKamw 
Extraction code: 3323

The above is the mysql-5.7 installation package. You can download it if necessary

Move to the directory where the installation package is stored and unzip the file

tar zxf mysql-boost-5.7.20.tar.gz

If you need to change the decompression path, you can specify it with - C and install it in the current directory by default

Next, move to the target directory

cd mysql-5.7.20/

2. Installation dependent environment

yum -y install ncurses ncurses-devel bison cmake

3. Create a user

Set the permissions of the new user to be unable to log in and connect to the mysql database

useradd -M -s /sbin/nologin mysql

4. cmake parsing

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

5. make compile install

make && make install

After the compilation starts, you need to wait for a period of time and wait for 100% installation

2, Modify profile

After installation, you can proceed to the next step

1. Change primary group

chown -R mysql:mysql /usr/local/mysql

After installation, a mysql folder will be automatically generated in the local directory under usr, but now the primary group belongs to the current user, not the mysql user, so it needs to be modified manually

2. Enter configuration file

vim /etc/my.cnf

Under this file, the basic configurations such as mysql character type and log file format are written. You need to enter to configure

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

You can directly modify the original file to the one shown in the figure above. You can directly delete or comment out the original command

3. Modify the primary group of the profile

chown mysql:mysql /etc/my.cnf

4. Setting environment variables

echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile

5. Initialize database

Move to mysql directory

cd /usr/local/mysql/

Initialize mysql

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

Directly execute mysql in bin under the current directory, specify database name, database path, log storage location and other configuration commands

6. Add launcher

Move to the storage location of the startup program

cd usr/lib/systemd/system

Copy and paste the startup file into the executable directory

cp mysqld.service /lib/systemd/system/

Verify that the addition was successful

systemctl enable mysqld.service

7. Open service

Open service

systemctl start mysqld.service

Set the password for mysql login, because there is no password by default. You can enter mysql directly, and the password is a little guaranteed

mysqladmin -u root -p password 'password'

Because it is now in an unclassified state, after entering the above command, you will be asked to enter the password and go to the next step directly

8. Enter database

mysql -u root -p

Enter the password you set before to log in

After these operations are completed, the mysql database is successfully built and can be used normally.

Topics: Database MySQL server