[Mysql] Install mysql-5.7.31 under linux

1. Download

Go to the mysql official website to download your own version of mysql,

Download link: https://dev.mysql.com/downloads/mysql/5.7.html#downloads

I download the mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz version here

You can also use the command to download after entering linux

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

Two, environment configuration

Before installation, we can check whether the system comes with MySQL installed:

rpm -qa | grep mysql

If yes, similar

mysql-libs-5.1.52-1.el6_0.1.x86_64

You can choose to uninstall:

rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64  // 普通删除模式

rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

Check if there is a mariadb database, if so, uninstall it, same as above

rpm -qa | grep mariadb

 If yes, similar

mariadb-libs-5.5.56-2.el7.x86_64

Then uninstall

rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

Use WinSCP 5.14.4 tool to upload the downloaded mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz to the /opt/mysql directory of the linux server

Three, installation

tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C ../servers/

Rename

mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql-5.7.31

Add system mysql group and mysql user

Check whether the mysql group and user exist, if not created

cat /etc/group | grep mysql

#类似

mysql:x:490:

cat /etc/passwd | grep mysql

#类似

mysql:x:496:490::/home/mysql:/bin/bash

The above is the existing situation, if not, execute the add command:

groupadd mysql

useradd -r -g mysql mysql


#useradd -r参数表示mysql用户是系统用户,不可用于登录系统

Install the database

Create data directory

cd mysql-5.7.31

mkdir data

 

Change the owner and group of /opt/mysql/mysql-5.7.31 to mysql

chown -R mysql:mysql /export/servers/mysql-5.7.31

Create my_default.cnf in the /export/servers/mysql-5.7.31/support-files directory

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.


[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

basedir = /export/servers/mysql-5.7.31
datadir = /export/servers/mysql-5.7.31/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8

log-error = /export/servers/mysql-5.7.31/data/mysqld.log
pid-file = /export/servers/mysql-5.7.31/data/mysqld.pid

Copy, if prompted whether to overwrite, y

cp support-files/my_default.cnf /etc/my.cnf

Initialize mysqld

cd /export/servers/mysql-5.7.31
./bin/mysqld --initialize --user=mysql --basedir=/export/servers/mysql-5.7.31 --datadir=/export/servers/mysql-5.7.31/data/

After the initialization is complete, check the log

/export/servers/mysql-5.7.31/data/mysqld.log

Temporary password

2019-04-08T06:14:29.790033Z 1 [Note] A temporary password is generated for root@localhost: a8?DQir=T+k+

Put the startup script in the boot initialization directory

cp support-files/mysql.server /etc/init.d/mysql

Start mysql service

service mysql start

Log in to mysql, the password is the initial password

 

cd /export/servers/mysql-5.7.31
./bin/mysql -u root -p
2020-09-23T09:29:18.970981Z 1 [Note] A temporary password is generated for root@localhost: .L6og)3HPuu1

change Password

mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@'%' identified by '123456';
mysql> flush privileges;

Add remote access permissions 

mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;

This error may appear here

ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'

If ERROR 1062 (23000): Duplicate entry'%-root' for key'PRIMARY' error appears when executing the update statement, it means that there are multiple ROOT users recorded in the USER table.

需要select host from user where user = 'root';

Check if the host already has the value of %, and that's it.

Restart mysql to take effect

service mysql stop
service mysql start

 or

service mysql restart

 

Guess you like

Origin blog.csdn.net/qq_44065303/article/details/108757866