Tutorial on installing mysql8 on linux centos7

Tutorial on installing mysql8 on linux centos7

1. RPM version installation

Check if there are other versions of the database, if so, delete them cleanly

Non-root users must have sudo privileges

1. Download MySQL related installation package

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-server-8.0.18-1.el7.x86_64.rpm

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-libs-8.0.18-1.el7.x86_64.rpm

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-common-8.0.18-1.el7.x86_64.rpm

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el7/mysql-community-client-8.0.18-1.el7.x86_64.rpm

2. Other dependencies (you can skip this step and install the dependencies you need to see when you install MySQL later)

Go to this website to find gcc, gcc-c++, openssl, perl and their dependent packages

https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/

3. Install MySQL (if no error is reported, the installation is successful)

4. Customize MySQL configuration (if you do not want to change the default MySQL related directory, skip to step 6)

Modify the default configuration file content of Mysql

sudo vi /etc/my.cnf

Delete all content and add the following:

[mysqld]
user=mysql
port=3306
datadir=/app/mysql/data
socket=/app/mysql/mysql.sock
log-error=/app/mysql/log/mysqld.log
pid-file=/app/mysql/mysqld.pid
[client]
socket=/app/mysql/mysql.sock

5. Create relevant directories in the configuration file and modify permissions

sudo mkdir /app/mysql/data /app/mysql/log -p
sudo chown mysql:mysql /app/mysql -R

6. Initialize mysql

7. Start mysql

If startup fails:

a. Check whether the user and group of the mysql related directory are mysql

b. Check whether selinux is turned off: execute sudo getenforce. If the result is not Permissive, execute the command: sudo setenforce 0

c. Check whether the port is occupied

d. If it still cannot start: check the mysql error log and sudo systemctl status mysqld or journalctl -xe

8. Log in to mysql

Check the initial password of Mysql (root@localhost: the following is the initial password)

sudo cat /app/mysql/log |grep root@localhost (used this command in step 4)
sudo cat /var/log/mysqld.log|grep root@localhost (this command has not been used in step 4)

Log in to mysql and copy the password above

mysql -p

9. Change the mysql password (the password must be changed for the first login, otherwise the mysql command cannot be used)

alter user 'root'@'localhost' identified by 'your password';

2. Source code installation

Non-root users must have sudo privileges

1. Download the relevant source code package

https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/gnu/gmp/gmp-6.2.0.tar.xz
https://mirrors.tuna.tsinghua.edu.cn/gnu/m4/m4-latest.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/gnu/mpfr/mpfr-4.0.2.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/gnu/mpc/mpc-1.1.0.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/mysql-8.0.19.tar.gz
http://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz
https://down.24kplus.com/linux/cmake/cmake-3.16.2.tar.gz

2. Install lower versions of gcc and gcc-c++ (must be done, otherwise configure will report an error when upgrading gcc and installing m4/gmp/mpfr/mpc: configure: error: no acceptable C compiler found in $PATH)

Go to this website and search for gcc, gcc-c++ and their dependent packages (if you can connect to the Internet, you can directly use the command: sudo yum -y install gcc gcc-c++)
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/

3. Install the source version of cmake

You must install openssl and openssl-devel dependencies, the download URL is the same as above, otherwise bootstrap will report an error: openssl cannot be found (if you can connect to the external network, you can directly use the command: sudo yum -y install openssl openssl-devel)

tar cmake-3.16.1.tgz
cd cmake-3.16.1
sudo ./bootstrap 
sudo make 
sudo make check
sudo make install

4. Upgrade gcc and gcc-c++

a. Install m4

tar -xzvf m4-latest.tar.gz
cd m4-1.4.17/
sudo ./configure --prefix=/usr/local (--prefix specifies the installation path)
sudo make (compile)
sudo make check (check if there are any errors in the compilation, pay attention to whether there are any Errors, you can skip this step)
sudo make install (Installation)
m4 --version (check m4 version)

After correct installation, you can see the following results

b. Install gmp

sudo ln -s /usr/local/bin/m4 /usr/bin (Make a soft link of m4 to this path, otherwise configure will report an error: checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).)
tar -xvf gmp-6.2.0.tar.xz
cd gmp-6.2.0
sudo ./configure --prefix=/usr/local/gmp-6.2 (non-administrators must use sudo, otherwise an error will be reported: Permission denied)
sudo make
sudo make check
sudo make install

c. Install mpfr

tar -xzvf mpfr-4.0.2.tar.gz 
cd mpfr-4.0.2 
sudo ./configure --prefix=/usr/local/mpfr-4.0 --with-gmp=/usr/local/gmp-6.2 (--with-gmp is the installation directory of gmp)
sudo make
sudo make check
sudo make install

d. Install mpc

tar -xzvf mpc-1.1.0.tar.gz
cd-mpc-1.1
sudo ./configure --prefix=/usr/local/mpc-1.1 --with-gmp=/usr/local/gmp-6.2 --with-mpfr=/usr/local/mpfr-4.0
sudo make
sduo make check
sudo make install

e. Add library files (/usr/local/mpfr-4.0/lib/ must be added, the other two can be omitted, otherwise an error will be reported when installing and upgrading gcc compilation: error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory)

sudo vi /etc/ld.so.conf
 /usr/local/mpfr-4.0/lib/

 /usr/local/gmp-6.2/lib

 /usr/local/mpc-1.1/lib

sudo ldconfig (make the above operation effective)

Or make a soft connection

sudo ln -s /usr/local/mpfr-4.0/lib/libmpfr.so.6 /usr/bin

Or copy

sudo cp /usr/local/mpfr-4.0/lib/libmpfr.so.6 /usr/bin/

f. Install other dependencies (if the system does not have the dependency package installed, it must be installed, otherwise an error will be reported when upgrading gcc compilation: mpc.h: no such file or directory)

Download gmp-devel and libmpc-devel and their dependent packages (if you can connect to the Internet, you can directly use the command: sudo yum -y install gmp-devel libmpc-devel)

https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/gmp-6.0.0-15.el7.x86_64.rpm
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/gmp-devel-6.0.0-15.el7.x86_64.rpm
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/libmpc-1.0.1-3.el7.x86_64.rpm
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/libmpc-devel-1.0.1-3.el7.x86_64.rpm
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/mpfr-3.1.1-4.el7.x86_64.rpm
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/mpfr-devel-3.1.1-4.el7.x86_64.rpm

If there are other dependent packages to download, please go to https://mirrors.tuna.tsinghua.edu.cn to download them yourself

g. Upgrade gcc

tar -xzvf gcc-9.2.0.tar.gz
cd gcc-9.2.0
 sudo ./configure --prefix=/usr/local/gcc-9.2 \
 --enable-bootstrap\
 --enable-checking=release \
 --enable-languages=c,c++ \
 --enable-threads=posix \
 --disable-checking\
 --disable-multilib\
 --enable--long-long\
 --with-gmp=/usr/local/gmp-6.2\
 --with-mpfr=/usr/local/mpfr-4.0\
 --with-mpc=/usr/local/mpc-1.1
sudo make (compilation time is long, about 1 hour)
sudo make check
sudo make install

Be sure to uninstall the lower version of gcc and gcc-c++

sudo rpm -e gcc-c++
sudo rpm -e gcc
sudo vi /etc/profile export PATH=$PATH:/usr/local/gcc/bin 
  source /etc/profile

Check the gcc version number

gcc --version

5. Install the source version of MySQL

Install ncurses-devel dependency, otherwise cmake will report an error: Curses library not found. Please install appropriate package (If you can connect to the Internet, you can directly use the command: sudo yum -y install ncurses-devel . If you cannot connect to the Internet, the download address is the same as step 2)

tar -xzvf mysql-8.0.19.tar.gz
cd mysql-8.0.19
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql\
 -DDEFAULT_CHARSET=utf8\
 -DDEFAULT_COLLATION=utf8_general_ci\
 -DENABLED_LOCAL_INFILE=ON\
 -DWITH_SSL=system\
 -DMYSQL_DATADIR=/app/mysql/data\
 -DSYSCONFDIR=/app/mysql/config\
 -DMYSQL_TCP_PORT=3306\
 -DMYSQL_UNIX_ADDR=/app/mysql/mysql.sock\
 -DWITH_BOOST=/home/mcbadm/mysql8/\
 -DFORCE_INSOURCE_BUILD=1

The above parameters are introduced as follows (simple parameters, for more detailed parameters, please refer to https://blog.51cto.com/laowafang/1294964): -DCMAKE_INSTALL_PREFIX: installation directory

-DDEFAULT_CHARSET: Set character set -DDEFAULT_COLLATION: Set collation -DENABLED_LOCAL_INFILE=ON: Enable local data import support -DWITH_SSL=system: Enable SSL library support -DMYSQL_DATADIR: Data file directory, any -DSYSCONFDIR: Configuration file directory, any -DMYSQL_TCP_PORT: TCP port that mysql listens on -DMYSQL_UNIX_ADDR: mysql.sock path, any -DWITH_BOOST: Boost source package directory -DFORCE_INSOURCE_BUILD: Force creation of non-existent resource directory If cmake reports an error, find the cause and solve it, delete CMakeCache.txt and cmake again

sudo rm -rf /usr/lib64/libstdc++.so.6* (delete all lower version c++ library files)
sudo ln -s /usr/local/gcc-9.2/lib64 /usr/lib64 (add the newly installed high-end C++ library file to the system library file)
sudo make (takes about 1 hour)
sudo make install

6. Write configuration files, create directories and authorize

sudo mkdir /app/mysql/config
sudo cd /app/mysql
sudo vi config/my.cnf

Add the following:

[mysqld]
user=mysql
port=3306
datadir=/app/mysql/data
socket=/app/mysql/mysql.sock
[mysqld_safe]
log-error=/app/mysql/logs/mysql-err.log
pid-file=/app/mysql/mysql.pid
[client]
socket=/app/mysql/mysql.sock
sudo useradd mysql -s /sbin/nologin
sudo mkdir -p /app/mysql/logs
sudo touch /app/mysql/logs/mysql-err.log
sudo chown -R mysql.mysql /app/mysql

7. Initialize and log in to change password

initialization

sudo /app/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/app/mysql/data --basedir=/app/mysql (no initial password, if you want an initial password, use --initialize)

start up

sudo /app/mysql/support-files/mysql.server start

Log in (if there is no initial password, just press Enter)

sudo /app/mysql/bin/mysql -p

Change Password

alter user 'root'@'localhost' identified by '密碼';

Summarize

The above is the tutorial on how to install mysql8 on linux centos7 introduced by the editor. I hope it will be helpful to everyone!

You may also be interested in:
  • Tutorial on installing mysql5.7.36 database in Linux environment
  • Introduction to the process of installing MySQL 8.0 in Linux environment
  • Detailed steps to install MySQL 8.0.27 in Linux 7.6 binary
  • Tutorial on installing MySQL under Linux
  • MySQL multi-instance deployment and installation guide under Linux
  • MySQL 8.0.25 installation and configuration tutorial under Linux
  • mysql8.0.23 linux (centos7) installation complete and detailed tutorial
  • Detailed tutorial on installing MySQL database in Linux environment
  • Detailed tutorial on installing mysql-8.0.20 under Linux
  • Linux system MySQL8.0.19 quick installation and configuration tutorial diagram
  • Install MySQL database in Linux environment

<<:  Detailed explanation of the process of installing msf on Linux system

>>:  WiFi Development | Introduction to WiFi Wireless Technology

Recommend

Detailed explanation of docker version es, milvus, minio startup commands

1. es startup command: docker run -itd -e TAKE_FI...

Learn SQL query execution order from scratch

The SQL query statement execution order is as fol...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

How to install JDK8 on Windows

1. Download: http://www.oracle.com/technetwork/ja...

InnoDB engine redo file maintenance method

If you want to adjust the size and number of Inno...

Detailed explanation of chmod command usage in Linux

chmod Command Syntax This is the correct syntax w...

Discussion on horizontal and vertical centering of elements in HTML

When we design a page, we often need to center th...

MySQL 8.0.18 Installation Configuration Optimization Tutorial

Mysql installation, configuration, and optimizati...

Web Design Experience: 5 Excellent Web Design Concepts Full Analysis (Pictures)

Unlike other types of design, web design has been ...

Concat() of combined fields in MySQL

Table of contents 1. Introduction 2. Main text 2....

How to configure nginx to limit the access frequency of the same IP

1. Add the following code to http{} in nginx.conf...

MySQL Series 12 Backup and Recovery

Table of contents Tutorial Series 1. Backup strat...