Install MYSQL-8.0.30 and MYSQL-5.7.28

#Install MYSQL-8.0.30

1. Installation preparation
According to the server version and CPU architecture (arch=x86_64), download the binary source package mysql-8.0.30-el7-x86_64.tar.gz and mysql-5.7.28-el7-x86_64.tar from the MYSQL official website. gz and save to the specified download directory /data/downloads/

2. Decompress the MYSQL source package
tar -zxvf mysql-8.0.30-el7-x86_64.tar.gz -C /data/
tar -zxvf mysql-5.7.28-el7-x86_64.tar.gz -C /data/

3. Add a new mysql user and use this user for MYSQL deployment
useradd mysql
chown -R mysql.mysql /data/mysql-8.0.30/
chown -R mysql.mysql /data/mysql-5.7.28/

4. Add the my.cnf configuration file, the basic parameter configuration reference is as follows
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ cat my.cnf
[client]
port = 3308
socket = /data /mysql-8.0.30/socket/mysqld-T-prod-3308.sock
default-character-set=utf8
[mysqld]
user = mysql
port = 3308
socket = /data/mysql-8.0.30/socket/mysqld-T -prod-3308.sock
datadir = /data/mysql-8.0.30/data
basedir = /data/mysql-8.0.30
server-id = 1
log-bin = /data/mysql-8.0.30/mylog/mysql- bin-T-prod-3308
sync-binlog=1
tmpdir = /data/mysql-8.0.30/tmp
[mysqld_safe]
pid-file = /data/mysql-8.0.30/pid/mysql-T-prod-3308. pid
log-error = /data/mysql-8.0.30/log/mysql-T-prod-3308.err
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ mkdir tmp
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ mkdir socket
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ mkdir mylog
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$

5.数据库初始化
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ bin/mysqld --defaults-file=/data/mysql-8.0.30/my.cnf --initialize
2022-09-30T07:43:55.588483Z 0 [System] [MY-013169] [Server] /data/mysql-8.0.30/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process 17783
2022-09-30T07:43:55.597319Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-30T07:43:56.192378Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-30T07:43:57.753087Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dc7/.MT6lm%o

6. Start the database
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ bin/mysqld --defaults-file=/data/mysql-8.0.30/my.cnf &

7. Use the socket method to access the database.
Use the "A temporary password is generated for root@localhost" password returned by initialization to change the password for the first access to the database, and add a new login user and authorization
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ ln -s /data/mysql-8.0.30/socket/mysqld-T-prod-3308.sock /tmp/mysql.sock
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ bin/mysql -uroot -p -P3308
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.30

Copyright © 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>
mysql> create user ‘root’@‘127.0.0.1’ identified by ‘123456’;
mysql> grant all privileges on . to ‘root’@‘127.0.0.1’ with grant option;
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

8. Use TCP to access the database (-h access host IP -P accessed MYSQL service port)
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ bin/mysql -uroot -h 127.0.0.1 -p -P3308
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.30 MySQL Community Server - GPL
insert image description here

#Install MYSQL-5.7.28

[mysql@ecs-x-large-2-linux-20200226154258 mysql-5.7.28]$ ln -s /data/mysql-5.7.28/socket/mysqld-T-prod-3306.sock /tmp/mysql.sock
[mysql@ecs-x-large-2-linux-20200226154258 mysql-5.7.28]$ bin/mysql -uroot -p -P3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28-log

Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>
mysql> alter user root@localhost identified by ‘123456’;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.00 sec)

mysql> select version();
±-----------+
| version() |
±-----------+
| 5.7.28-log |
±-----------+
1 row in set (0.00 sec)

mysql> grant all privileges on . to ‘root’@‘%’ identified by ‘123456’;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
[mysql@ecs-x-large-2-linux-20200226154258 mysql-5.7.28]$ bin/mysql -uroot -p -h 127.0.0.1 -P 3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.28-log MySQL Community Server (GPL)
insert image description here

The background of this installation is to quickly install two versions of MYSQL-8.0.30 and MYSQL-5.7.28 on the same server (the installation steps of the two versions are basically the same, so only the installation steps of MYSQL-8.0.30 are written in detail) . During the installation process, there are two problems: the /tmp/mysql.sock file is required to access the database in socket mode and the need to create user information before authorizing new users in MYSQL-8.0.30. The solutions are recorded in the process. There are many reference documents on the Internet for the steps to install MYSQL on a Linux server. Here is another one, and if you get it, you must share it.

Guess you like

Origin blog.csdn.net/Wemesun/article/details/127126258