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

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


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/ [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

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)

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 cannot open shared object file: no such file or directory)

sudo vi /etc/



sudo ldconfig (Make the above operation effective)

Or make a soft connection

sudo ln -s /usr/local/mpfr-4.0/lib/ /usr/bin

Or copy

sudo cp /usr/local/mpfr-4.0/lib/ /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)

If you still have dependent packages to download, go to 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-checking=release \
  --enable-languages=c,c++ \
  --enable-threads=posix \

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\

The above parameters are described below (simple parameters, more detailed parameters refer to
-DCMAKE_INSTALL_PREFIX: Installation Directory
-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/* (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/ [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

 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)

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