Linux系统CentOS 8.*部署MySQL5.7+MySQL8.0双料实例
CentOS 8.*部署MySQL5.7.33+MySQL8.0.21双料实例指南介绍
MySQL安装部署方法多样,版本多样性:
1、glibc版安装
2、yum安装
3、rpm安装
4、源码安装
5、tar包安装
部署环境
1、阿里云4G816G,CentOS Linux release 8.2.2004 (Core)
2、MySQL-5.7.33,监听3307端口
3、MySQL-8.0.21,监听3306端口
一、下载MySQL5.7.33、MySQL8.0.21
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
将MySQL5.7.33、MySQL8.0.21 URL粘贴到迅雷或浏览器地址栏,下载即可;
二、上传并解压至安装目录
[root@localhost ~]# rz //此处上传方法视习惯,ftp、辅助软件皆可
[root@localhost opt]# ll
总用量 985876
-rw-r--r-- 1 root root 661718255 5月 7 11:56 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 root root 347814208 5月 7 11:56 mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz
[root@localhost opt]# tar -xvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost opt]# tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
...此处略过千百行...
三、创建MySQL5.7.33启动相关文档与DATA数据文件夹
1、规范MySQL5.7.33、MySQL8.0.21目录
[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64 mysql-5.7.33
[root@localhost local]# mv mysql-8.0.21-linux-glibc2.12-x86_64 mysql-8.0.21
[root@localhost local]# cd mysql-5.7.33
[root@localhost mysql-5.7.33]# vim my.cnf //参考如下配置
[client]
port=3307
[mysql]
default-character-set=utf8mb4
[mysqld]
# MySQL服务器将监听的TCP/IP端口
port=3307
# 安装目录的路径。 通常相对于此解析所有路径。
basedir=/usr/local/mysql-5.7.33/
# 数据库根目录的路径
datadir=/usr/local/mysql-5.7.33/data
# 创建新模式或表且未定义任何字符集时将使用的默认字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# MySQL服务器允许的最大并发会话数。
# 这些连接中的一个将保留给具有超级权限的用户,以允许管理员登录,即使已达到连接限制。
max_connections=151
# soket文件,本地连接时使用
socket=/usr/local/mysql-5.7.33/logs/mysql.sock
# 建议禁用符号链接以防止各种安全风险
symbolic-links=0
# 错误日志
log-error=/usr/local/mysql-5.7.33/logs/mysqld.log
# pid文件
pid-file=/usr/local/mysql-5.7.33/logs/mysqld.pid
2、创建mysql启动用户与组
[root@localhost mysql-5.7.33]# useradd -s /sbin/nologin -M mysql //创建用户与组
[root@localhost mysql-5.7.33]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)
[root@localhost mysql-5.7.33]# mkdir {data,logs} //创建数据库data、logs目录
[root@localhost mysql-5.7.33]# ll
总用量 268
drwxr-xr-x 2 root root 4096 5月 7 11:57 bin
drwxr-xr-x 2 root root 6 5月 7 12:13 data
drwxr-xr-x 2 root root 55 5月 7 11:57 docs
drwxr-xr-x 3 root root 4096 5月 7 11:56 include
drwxr-xr-x 5 root root 230 5月 7 11:57 lib
-rw-r--r-- 1 7161 31415 250129 12月 10 11:01 LICENSE
drwxr-xr-x 2 root root 6 5月 7 12:13 logs
drwxr-xr-x 4 root root 30 5月 7 11:57 man
-rw-r--r-- 1 root root 969 5月 7 12:08 my.cnf
-rw-r--r-- 1 7161 31415 566 12月 10 11:01 README
drwxr-xr-x 28 root root 4096 5月 7 11:57 share
drwxr-xr-x 2 root root 90 5月 7 11:57 support-files
[root@localhost mysql-5.7.33]# chown -R mysql.mysql /usr/local/mysql-5.7.33/ //授予mysql用户完全权限
[root@localhost mysql-5.7.33]# ll
总用量 268
drwxr-xr-x 2 mysql mysql 4096 5月 7 11:57 bin
drwxr-xr-x 2 mysql mysql 6 5月 7 12:13 data
drwxr-xr-x 2 mysql mysql 55 5月 7 11:57 docs
drwxr-xr-x 3 mysql mysql 4096 5月 7 11:56 include
drwxr-xr-x 5 mysql mysql 230 5月 7 11:57 lib
-rw-r--r-- 1 mysql mysql 250129 12月 10 11:01 LICENSE
drwxr-xr-x 2 mysql mysql 6 5月 7 12:13 logs
drwxr-xr-x 4 mysql mysql 30 5月 7 11:57 man
-rw-r--r-- 1 mysql mysql 969 5月 7 12:08 my.cnf
-rw-r--r-- 1 mysql mysql 566 12月 10 11:01 README
drwxr-xr-x 28 mysql mysql 4096 5月 7 11:57 share
drwxr-xr-x 2 mysql mysql 90 5月 7 11:57 support-files
[root@localhost mysql-5.7.33]# /usr/local/mysql-5.7.33/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql-5.7.33 --datadir=/usr/local/mysql-5.7.33/data
3、创建mysql57.service启动文件
[root@localhost mysql-5.7.33]# vi /etc/systemd/system/mysqld57.service
[Unit]
Description=MySQL Server 5.7
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql-5.7.33/bin/mysqld --defaults-file=/usr/local/mysql-5.7.33/my.cnf
LimitNOFILE = max_open_files
4、启动MySQL-5.7.33进程
[root@localhost mysql-5.7.33]# systemctl start mysqld57
[root@localhost mysql-5.7.33]# netstat -lntp
5、客户端登录配置
[root@localhost mysql-5.7.33]# /usr/local/mysql-5.7.33/bin/mysql -S /usr/local/mysql-5.7.33/logs/mysql.sock
报错:/usr/local/mysql-5.7.33/bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解决办法:
[root@localhost mysql-5.7.33]# yum install ncurses-compat-libs -y
再次执行登录命令,OK
[root@localhost mysql-5.7.33]# /usr/local/mysql-5.7.33/bin/mysql -S /usr/local/mysql-5.7.33/logs/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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>
6、设置密码、授权root远程登录
mysql>select user,authentication_string,host from user;
+---------------+-------------------------------------------+-----------+
| user | authentication_string | host |
+---------------+-------------------------------------------+-----------+
| root | | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
+---------------+-------------------------------------------+-----------+
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'qwqw1212';
Query OK, 0 rows affected (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,authentication_string,host from user;
+---------------+-------------------------------------------+-----------+
| user | authentication_string | host |
+---------------+-------------------------------------------+-----------+
| root | *7804527F48ED7DAD2D5BE758470B49ED24A0519F | % |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
+---------------+-------------------------------------------+-----------+
3 rows in set (0.00 sec)
mysql> quit
四、创建MySQL8.0.21启动相关文档与DATA数据文件夹
1、接续MySQL-5.7.33步骤,制作my.cnf配置文件
[root@localhost local]# cd mysql-8.0.21
[root@localhost mysql-8.0.21]# vim my.cnf //参考如下配置
[client]
port=3306
[mysql]
default-character-set=utf8mb4
[mysqld]
# MySQL服务器将监听的TCP/IP端口
port=3306
# 安装目录的路径。 通常相对于此解析所有路径。
basedir=/usr/local/mysql-8.0.21/
# 数据库根目录的路径
datadir=/usr/local/mysql-8.0.21/data
# 创建新模式或表且未定义任何字符集时将使用的默认字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# MySQL服务器允许的最大并发会话数。
# 这些连接中的一个将保留给具有超级权限的用户,以允许管理员登录,即使已达到连接限制。
max_connections=151
# soket文件,本地连接时使用
socket=/usr/local/mysql-8.0.21/logs/mysql.sock
# 建议禁用符号链接以防止各种安全风险
symbolic-links=0
# 错误日志
log-error=/usr/local/mysql-8.0.21/logs/mysqld.log
# pid文件
pid-file=/usr/local/mysql-8.0.21/logs/mysqld.pid
2、创建mysql启动用户与组,此步骤在mysql-5.7.33以完成,无须重复创建,核验下即可
[root@localhost mysql-8.0.21]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)
[root@localhost mysql-8.0.21]# mkdir {data,logs}
[root@localhost mysql-8.0.21]# ll
总用量 408
drwxr-xr-x 2 7161 31415 4096 6月 17 2020 bin
drwxr-xr-x 2 root root 6 5月 7 14:15 data
drwxr-xr-x 2 7161 31415 55 6月 17 2020 docs
drwxr-xr-x 3 7161 31415 282 6月 17 2020 include
drwxr-xr-x 6 7161 31415 201 6月 17 2020 lib
-rw-r--r-- 1 7161 31415 404759 6月 17 2020 LICENSE
drwxr-xr-x 2 root root 6 5月 7 14:15 logs
drwxr-xr-x 4 7161 31415 30 6月 17 2020 man
-rw-r--r-- 1 7161 31415 687 6月 17 2020 README
drwxr-xr-x 28 7161 31415 4096 6月 17 2020 share
drwxr-xr-x 2 7161 31415 77 6月 17 2020 support-files
3、创建my.cnf文件
[root@localhost mysql-8.0.21]# vim my.cnf
[client]
port=3306
[mysql]
default-character-set=utf8mb4
[mysqld]
# MySQL服务器将监听的TCP/IP端口
port=3306
# 安装目录的路径。 通常相对于此解析所有路径。
basedir=/usr/local/mysql-8.0.21/
# 数据库根目录的路径
datadir=/usr/local/mysql-8.0.21/data
# 创建新模式或表且未定义任何字符集时将使用的默认字符集
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# MySQL服务器允许的最大并发会话数。
# 这些连接中的一个将保留给具有超级权限的用户,以允许管理员登录,即使已达到连接限制。
max_connections=151
# soket文件,本地连接时使用
socket=/usr/local/mysql-8.0.21/logs/mysql.sock
# 建议禁用符号链接以防止各种安全风险
symbolic-links=0
# 错误日志
log-error=/usr/local/mysql-8.0.21/logs/mysqld.log
# pid文件
pid-file=/usr/local/mysql-8.0.21/logs/mysqld.pid
4、授权MySQL8.0.21用户与组完全管理权限
[root@localhost mysql-8.0.21]# chown -R mysql.mysql /usr/local/mysql-8.0.21/
[root@localhost mysql-8.0.21]# ll
总用量 412
drwxr-xr-x 2 mysql mysql 4096 6月 17 2020 bin
drwxr-xr-x 2 mysql mysql 6 5月 7 14:15 data
drwxr-xr-x 2 mysql mysql 55 6月 17 2020 docs
drwxr-xr-x 3 mysql mysql 282 6月 17 2020 include
drwxr-xr-x 6 mysql mysql 201 6月 17 2020 lib
-rw-r--r-- 1 mysql mysql 404759 6月 17 2020 LICENSE
drwxr-xr-x 2 mysql mysql 6 5月 7 14:15 logs
drwxr-xr-x 4 mysql mysql 30 6月 17 2020 man
-rw-r--r-- 1 mysql mysql 972 5月 7 14:22 my.cnf
-rw-r--r-- 1 mysql mysql 687 6月 17 2020 README
drwxr-xr-x 28 mysql mysql 4096 6月 17 2020 share
drwxr-xr-x 2 mysql mysql 77 6月 17 2020 support-files
5、创建mysql80.service启动文件
[root@localhost mysql-8.0.21]# vi /etc/systemd/system/mysqld80.service
[Unit]
Description=MySQL Server 8.0
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql-8.0.21/bin/mysqld --defaults-file=/usr/local/mysql-8.0.21/my.cnf
LimitNOFILE = max_open_files
6、初始化MySQL8.0.21
[root@localhost /usr/local/mysql-8.0.21/bin/mysqld --defaults-file=/usr/local/mysql-8.0.21/my.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql-8.0.21 --datadir=/usr/local/mysql-8.0.21/data
2021-05-07T06:27:52.693712Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.21/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 63897
2021-05-07T06:27:52.725660Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-05-07T06:27:53.254345Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-05-07T06:27:54.179724Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option
7、启动MySQL8.0.21服务
[root@localhost mysql-8.0.21]# systemctl start mysqld80
[root@localhost mysql-8.0.21]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1535/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 979/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 981/cupsd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2543/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 979/sshd
tcp6 0 0 ::1:631 :::* LISTEN 981/cupsd
tcp6 0 0 ::1:6010 :::* LISTEN 2543/sshd: root@pts
tcp6 0 0 :::33060 :::* LISTEN 65475/mysqld
tcp6 0 0 :::3306 :::* LISTEN 65475/mysqld
tcp6 0 0 :::3307 :::* LISTEN 46511/mysqld
[root@localhost mysql-8.0.21]# /usr/local/mysql-8.0.21/bin/mysql -S /usr/local/mysql-8.0.21/logs/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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>
至此、CentOS 8.*部署MySQL5.7+MySQL8.0双料实例新手部署教程全部完成,有疑问留言交流;
Linux系统CentOS 8.*部署MySQL5.7+MySQL8.0双料实例
https://cn.10691.cn//archives/10020