1. Download the tar package, which is downloaded from the official website using wget
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
2. Install mysql under / usr/local/mysql
# decompression tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz # move mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/ # rename mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
3. New data directory
mkdir /usr/local/mysql/data
4. New mysql users, mysql user groups
# mysql user group groupadd mysql # mysql users useradd mysql -g mysql
5. Change the owner and group of / usr/local/mysql to mysql
chown -R mysql.mysql /usr/local/mysql
6. Initialize mysql
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize # If the following error occurs, execute the following command to install numactl and then re-execute the mysqld command above /usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory yum -y install numactl
7. Editing my.cnf
[mysqld] datadir=/usr/local/mysql/data basedir=/usr/local/mysql socket=/tmp/mysql.sock user=mysql port=3306 character-set-server=utf8 # Cancel password validation skip-grant-tables # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # skip-grant-tables [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
8. Opening Services
# Add mysql to the service cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql # Boot from boot chkconfig mysql on # service mysql start service mysql start
9. Setting Password
# Log in (because password authentication is cancelled in / etc/my.cnf, the password here is arbitrary) /usr/local/mysql/bin/mysql -u root -p # Operating mysql database >use mysql; # Change Password >update user set authentication_string=password('Your password') where user='root'; >flush privileges; >exit;
10. Delete skip-grant-tables from / etc/my.cnf
11. Log in and set the password again (I don't know why I can't operate the database without setting the password again)
/usr/local/mysql/bin/mysql -u root -p >ALTER USER 'root'@'localhost' IDENTIFIED BY 'Modified password'; >exit;
12. Allow remote connection
/usr/local/mysql/bin/mysql -u root -p >use mysql; >update user set host='%' where user = 'root'; >flush privileges; >eixt;
13. Add shortcuts
ln -s /usr/local/mysql/bin/mysql /usr/bin
- Create a database
CREATE DATABASE `testdb` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; # Permanently disable firewalls (virtual machines need to be restarted) systemctl disable firewalld.service reboot # Check the IP address on the virtual machine ifconfig
15. Remote connection mysql
mysql -h 172.16.128.128 -u root -p > show databases;