安装MYSQL-8.0.30和MYSQL-5.7.28

#安装MYSQL-8.0.30

1.安装准备
根据服务器的版本和CPU架构(arch=x86_64),在MYSQL官网下载二进制源码包mysql-8.0.30-el7-x86_64.tar.gz和mysql-5.7.28-el7-x86_64.tar.gz并保存到指定下载目录/data/downloads/

2.解压MYSQL源码包
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.新增mysql用户并使用该用户进行MYSQL部署
useradd mysql
chown -R mysql.mysql /data/mysql-8.0.30/
chown -R mysql.mysql /data/mysql-5.7.28/

4.新增my.cnf配置文件,基本参数配置参考如下
[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.启动数据库
[mysql@ecs-x-large-2-linux-20200226154258 mysql-8.0.30]$ bin/mysqld --defaults-file=/data/mysql-8.0.30/my.cnf &

7.使用socket方式访问数据库
使用初始化最终返回的"A temporary password is generated for root@localhost"密码首次访问数据库改密,新增登录用户及授权
[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.使用TCP方式访问数据库(-h 访问主机IP -P 被访问的MYSQL服务端口)
[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
在这里插入图片描述

#安装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)
在这里插入图片描述

本次安装背景是在同一台服务器上快速安装MYSQL-8.0.30和MYSQL-5.7.28两个版本,(两个版本安装步骤基本相同,故只详写了MYSQL-8.0.30的安装步骤)。安装过程中遇到socket方式访问数据库需要/tmp/mysql.sock文件和在MYSQL-8.0.30中给新增用户授权前需要先创建用户信息两个问题,解决方案都记录在了过程中。在Linux服务器上安装MYSQL的步骤网上有很多参考文档,这里再加一份,有获得就要有分享。

猜你喜欢

转载自blog.csdn.net/Wemesun/article/details/127126258