linux centos7 install mysql8

1. RPM version installation

Check to see if there are other versions of the database, and if so, delete it clean

Non-root users must have sudo privileges

1. Download mysql related installation packages

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 any dependencies you lack when installing 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 (no error indicates successful installation)

4. Customize the configuration of MySQL (skip to step 6 if you don't want to change mysql's default related directory)

modify Mysql Default profile content

sudo vi /etc/my.cnf
Delete all content,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 related 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 error:

a. Check to see if the user and group belonging to the directory related to mysql are mysql

b. Check to see if selinux is off: executing sudo getenforce yields a result other than Permissive, executing the command sudo setenforce 0

c. Check if the port is occupied

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

8. Log in to mysql

View Mysql's initial password (root@localhost: followed by 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 (you did not use this command in step 4)

Log in to mysql and copy the password above
mysql -p

9. Modify mysql password (password must be changed for initial login or mysql command cannot be used)

 

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

 

 

2. Source Version Installation

Non-root users must have sudo privileges

1. Download related source packages

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 a lower version of gcc, gcc-c++ (must do otherwise, configure will fail when upgrading GCC to install m4/gmp/mpfr/mpc: configure: error: no acceptable C compiler found in $PATH)

Find gcc, gcc-c++, and their dependent packages under this web address (sudo yum-y install gcc-c++, which can be used directly from an external network)
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/

3. Install source cmake


You must install OpenSSL and openssl-devel dependencies, or the download URL is the same, or bootstrap will error: OpenSSL cannot be found (you can connect to an external network directly with 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, 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
sudo make check
sudo make install

m4--version (see m4 version)

After correct installation, you can see the following results

b. Install gmp

Sudo Ln-S /usr/local/bin/m4/usr/bin (make M4 a soft connection to this path, otherwise configure will get an error: checking for suitable m4... configure: error: No usable M4 in $PATH or /usr/5bin (see config.log reasons for).)
tar -xvf gmp-6.2.0.tar.xz
cd gmp-6.2.0
Sudo. /configure --prefix=/usr/local/gmp-6.2 (non-administrators must sudo or error: 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 by gmp Installation directory for)
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 add library files, the other two can not be done, otherwise an error will occur when installing upgrade gcc compilation: error loading shared libraries: lib mpfr.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 (system must install dependency packages when they are not installed, otherwise upgrade gcc compilation will result in an error: mpc.h: no file or directory)

download gmp-devel and libmpc-devel And its dependent packages(Commands can be used directly when connecting to an external network: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 you still have dependent packages to download, go to
https://mirrors.tuna.tsinghua.edu.cn Download by 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 (Compile time is long,1 What it looks like in an hour)
sudo make check
sudo make install

Be sure to uninstall the lower version gcc,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
See gcc version number
gcc --version

 

5. Install source version mysql

Install ncurses-devel dependency, otherwise cmake error: Curses library not found.Please install appropriate package (can connect to the outside network directly using the command: sudo yum-y install ncurses-devel, cannot connect to the outside network download address as in 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 described below (simple parameters, more detailed parameters 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, optional
-DSYSCONFDIR: Profile directory, optional
-DMYSQL_TCP_PORT:TCP port MySQL listens on
-DMYSQL_UNIX_ADDR:mysql.sock path, optional
-DWITH_BOOST:boost source package directory
-DFORCE_INSOURCE_BUILD: Force the creation of non-existent resource directories
If cmake fails, please find the cause and remove CMakeCache.txt to make cmake again

Sudo rm-rf/usr/lib64/libstdc++.so.6* (delete all library files for lower version c++)
Sudo Ln-S /usr/local/gcc-9.2/lib64/usr/lib64 (add newly installed high-quality c++ library files to system library files)
sudo make (takes about an 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 (if you do not have an initial password, use --initialize)

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

Login (Enter directly without initial password)
sudo /app/mysql/bin/mysql -p

Change Password
Alter user'root'@'localhost'identified by'password';

Keywords: Linux MySQL sudo RPM cmake

Added by jmcall10 on Sat, 25 Jan 2020 10:42:23 +0200