Teach you how to compile and install MySQL database and explain the commands (version 5.7)

One, the environment dependency package required to install MySQL

[root@localhost opt]# yum -y install \
gcc \
gcc-c++ \
make \
ncurses \
ncurses-devel \
bison \
cmake

Environment dependent package description

gcc C language compiler
gcc-c++ C++ compiler
make Source code compilation (source code is converted into binary files)

2. Create a running account

[root@localhost ~]# useradd -s /sbin/nologin  mysql

Three, compile and install

[root@localhost ~]# cd /opt
[root@localhost opt]# tar xzvf mysql-boost-5.7.20.tar.gz
[root@localhost opt]#cd /opt/mysql-5.7.20/
[root@localhost mysql-5.7.20]#
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

[root@localhost mysql-5.7.20]#make -j3
[root@localhost mysql-5.7.20]#make install

Configuration options meaning

  • DCMAKE_INSTALL_PREFIX: Specifies to install the mysql database program to a certain directory, such as the directory /usr/local/mysql.

  • DMYSQL_UNIX_ADDR: Specify the storage path of the socket file, the file connected to the database

  • DSYSCONFDIR: Specify the initialization parameter file directory

  • DDEFAULT_CHARSET: Specify the character set encoding used by default, such as utf8.

  • DDEFAULT_COLLATION: Specify the collation rules for the default character set, utf8_general_ci is a general rule for UTF-8 character set.

  • DWITH_INNOBASE_STORAGE_ENGINE=1: Install the INNOBASE storage engine

  • DWITH_ARCHIVE_STORAGE_ENGINE=1: Install the ARCHIVE storage engine

  • DWITH_BLACKHOLE_STORAGE_ENGINE=1: Install the ARCHIVE storage engine

  • DWITH_PERFSCHEMA_STORAGE_ENGINE: Install FEDERATED storage engine

  • DMYSQL_DATADIR=/data/mysql: data installation path

To explicitly specify not to compile a storage engine, you can use an option similar to the following:
-DWITHOUT__STORAGE_ENGINE=1

If you want to compile into other functions, such as SSL, you can use options like the following to use a library or not use a library when compiling:
-DWITH_READLINE=1
-DWITH_SSL=system means to use the built-in SSL library on the system
-DWITH_ZLIB =system
-DWITH_LIBWRAP=0

Other commonly used options:
-DMYSQL_TCP_PORT=3306: Set the default port
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock: The location of the socket for MySQL inter-process communication
-DENABLED_LOCAL_INFILE=1: Whether to start the local LOCAL_INFILE
-DEXTRA_CHARSETS=all: Support Which additional character sets-
DDEFAULT_CHARSET=utf8: the default character set-
DDEFAULT_COLLATION=utf8_general_ci: the default character set collation-
DWITH_DEBUG=0: whether to enable the DEBUG function-
DENABLE_PROFILING=1: whether to enable the performance analysis function

Note :

  • If there is an error in the process
    of CMAKE-after the error is resolved, you need to delete the CMakeCache.txt file in the source directory, and then re-CMAKE, otherwise the error remains.
  • 报错:make: *** No targets specified and no makefile found. Stop.解决方法
    1、wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
    2.、tar zxvf ncurses-5.6.tar.gz
    3、 ./configure -prefix=/usr/local -with-shared-without-debug
    4、make
    5、make install

Four, database directory permissions modification

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

Five, modify the configuration file

vi /etc/my.cnf

[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

[root@localhost ~]# chown mysql:mysql /etc/my.cnf

Six, set environment variables

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

Seven, initialize the database

cd /usr/local/mysql/

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

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
netstat -anpt | grep 3306

8. Set the login password and log in to the database

mysqladmin -u root -p password "abc123" ##刚开始没密码是空的直接回车,然后输入密码abc123,在此确认abc123,这是在root账户下运行的
mysql -u root -p     ##这个命令敲下,提示要输入密码,这个就是刚才设置的密码abc123,可登录数据库

Guess you like

Origin blog.csdn.net/qq_41786285/article/details/109314823