CentOS7 安装mysql8.0 glibc版,tar.gz,tar.xz

一、说明

个人感觉,glibc版的,好配置多版本、多实例。同一版本也方便配置多实例。

mysql安装方式很多:

1.glibc版,tar.gz,tar.xz

CentOS7.7下二进制部署MySQL多版本多实例实战

2.yum安装

CentOS 8 安装 MySQL 5.7 或 MySQL 8

A Quick Guide to Using the MySQL Yum Repository

CentOS 8 安装MySQL 8.0

3.rpm安装

4.源码安装

5.tar包

二、下载地址

MySQL :: Download MySQL Community Server

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

https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz

三、安装MySQL8.0

1.上传,解压,重命名

[root@dev1 opt]# tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@dev1 opt]# mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0.20

2.创建配置文件my.cnf

[root@dev1 opt]# cd mysql-8.0.20/
[root@dev1 mysql-8.0.20]# vi my.cnf

[client]
port=3308

[mysql]
default-character-set=utf8mb4
 
[mysqld]
# MySQL启动用户
user=mysql

# 服务器侦听TCP/IP连接的端口号。
port=3308

# MySQL安装基础目录的路径。
basedir=/opt/mysql-8.0.20

# MySQL服务器数据目录的路径。最好将datadir值指定为绝对路径。
datadir=/opt/mysql-8.0.20/data

# 服务器默认字符集。如果设置此变量,还应设置collation_server以指定字符集的排序规则。
character-set-server=utf8mb4

# 服务器的默认排序规则。
collation_server=utf8mb4_0900_ai_ci

# 表的默认存储引擎。此变量仅为永久表设置存储引擎。
# 要为临时表设置存储引擎,请设置default_tmp_storage_engine系统变量。
default-storage-engine=InnoDB

# 允许的最大同时客户端连接数。(1-100000)
max_connections=151

# 在max_connect_errors之后,来自主机的连续连接请求在没有成功连接的情况下被中断,服务器将阻止该主机进行进一步的连接。
max_connect_errors=100

# 默认的身份验证插件。(mysql_native_password,sha256_password,caching_sha2_password)
default_authentication_plugin=caching_sha2_password

# soket文件,本地连接时使用
socket=/opt/mysql-8.0.20/data/mysql.sock

# 建议禁用符号链接以防止各种安全风险
symbolic-links=0

# 错误日志
log-error=/opt/mysql-8.0.20/data/mysqld.log

# pid文件
pid-file=/opt/mysql-8.0.20/data/mysqld.pid

# 表名不区分大小写(修改后需要重新初始化mysql)
lower_case_table_names=1

# 设置sql_mode(没有NO_AUTO_CREATE_USER了)
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

3.创建用户

-s /sbin/nologin 指定用户登入后所使用的shell。默认值为/bin/bash。/sbin/nologin,无法使用shell

-M:不要自动建立用户的登入目录。

[root@dev1 mysql-8.0.20]# useradd -s /sbin/nologin -M mysql
useradd:用户“mysql”已存在
[root@dev1 mysql-8.0.20]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)

[root@dev1 mysql-8.0.20]# chown -R mysql.mysql /opt/mysql-8.0.20

4.初始化

--initialize-insecure 密码为空

[root@dev1 mysql-8.0.20]# /opt/mysql-8.0.20/bin/mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql-8.0.20 --datadir=/opt/mysql-8.0.20/data --lower_case_table_names=1
[Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

如果my.cnf配置了lower_case_table_names=1,初始化时也叫加上--lower_case_table_names=1

否则报错:

tail -f /opt/mysql-8.0.20/data/mysqld.log
[Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').

如果报错:

error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

安装libiao

yum install libaio

5.创建service文件

[root@dev1 mysql-8.0.20]# vi /usr/lib/systemd/system/mysqld80.service

或  vi /etc/systemd/system/mysqld80.service

[Unit]
Description=MySQL Server 8.0
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=/opt/mysql-8.0.20/bin/mysqld --defaults-file=/opt/mysql-8.0.20/my.cnf
LimitNOFILE = max_open_files

6.启动服务

[root@dev1 mysql-8.0.20]# systemctl start mysqld80
[root@dev1 mysql-8.0.20]# netstat -lntup|grep mysqld
tcp6       0      0 :::33060                :::*                    LISTEN      9129/mysqld         
tcp6       0      0 :::3305                 :::*                    LISTEN      7479/mysqld         
tcp6       0      0 :::3308                 :::*                    LISTEN      9129/mysqld

7.设置自启动

[root@bogon mysql-8.0.20]# systemctl enable mysqld80

8.客户端登录

[root@dev1 log]# /opt/mysql-8.0.20/bin/mysql -S /opt/mysql-8.0.20/data/mysql.sock
mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.20    |
+-----------+
1 row in set (0.00 sec)

mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3308  |
+---------------+-------+
1 row in set (0.01 sec)

9.修改密码,允许远程登录

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,authentication_string,host from user;
+------------------+------------------------------------------------------------------------+-----------+
| user             | authentication_string                                                  | host      |
+------------------+------------------------------------------------------------------------+-----------+
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| root             |                                                                        | localhost |
+------------------+------------------------------------------------------------------------+-----------+
4 rows in set (0.00 sec)

mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

四、主从复制

CentOS7 mysql8.0 主从复制

五、MGR集群

mysql8 MGR集群安装,组复制,单主模式,多主模式

六、文档

MySQL 8.0 Reference Manual

2.2 Installing MySQL on Unix/Linux Using Generic Binaries

2.3.4.2 Creating an Option File

4.2.2.2 Using Option Files

5.1.2 Server Configuration Defaults

5.1.7 Server Command Options

5.1.8 Server System Variables (my.cnf中的属性的解释及默认值)

10.4 Connection Character Sets and Collations

17.1.6 Replication and Binary Logging Options and Variables (主从复制)

七、yum安装mysq8.0默认配置文件(配置参考)

/etc/my.cnf

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

/etc/my.cnf.d/client.cnf

#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#


[client]

# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]

/etc/my.cnf.d/mysql-default-authentication-plugin.cnf

#
# MySQL 8.0.4 introduced 'caching_sha2_password' as its default authentication plugin.
# It is faster and provides better security then the previous default authentication plugin.
#
# Until now (09/2018), it does not work with some other software (eg. MariaDB client, MariaDB connectors,  ...)
#
# This configuration file changes MySQL default server configuration, so it behaves the same way as in MySQL 5.7.
#
# To change the behaviour back to the upstream default, comment out the following lines:

[mysqld]
default_authentication_plugin=mysql_native_password

/etc/my.cnf.d/mysql-server.cnf

#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid

好的,你可以按照以下步骤在CentOS安装mysql-8.tar.gz本的MySQL: 1. 首先,下载mysql-8.tar.gz包,可以使用以下命令在终端或命令行工具中进行下载: ``` wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.25-linux-glibc2.17-x86_64.tar.gz ``` 注意:以上下载地址是mysql-8.0.25本的下载地址,如果需要安装其他本的MySQL,请修改下载地址。 2. 下载完成后,解压mysql-8.tar.gz包,可以使用以下命令进行解压: ``` tar -zxvf mysql-8.0.25-linux-glibc2.17-x86_64.tar.gz ``` 3. 将解压后的mysql-8.0.25-linux-glibc2.17-x86_64目录移动到/usr/local目录下: ``` mv mysql-8.0.25-linux-glibc2.17-x86_64 /usr/local/mysql ``` 4. 进入/usr/local/mysql目录,执行以下命令初始化MySQL: ``` cd /usr/local/mysql bin/mysqld --initialize --user=mysql ``` 5. 修改MySQL配置文件/etc/my.cnf,添加以下内容: ``` [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysql/error.log pid-file=/var/run/mysql/mysql.pid ``` 注意:以上配置文件中的参数可以根据你的需要进行修改。 6. 创建MySQL运行所需的目录: ``` mkdir /var/run/mysql mkdir /var/log/mysql chown -R mysql:mysql /var/run/mysql chown -R mysql:mysql /var/log/mysql ``` 7. 启动MySQL服务: ``` bin/mysqld_safe --user=mysql & ``` 8. 设置root用户密码: ``` bin/mysql_secure_installation ``` 按照提示,设置root用户密码。 9. 远程连接MySQL: ``` bin/mysql -u root -p ``` 输入密码后,即可进入MySQL命令行界面。 至此,你已经成功在CentOS安装mysql-8.tar.gz本的MySQL
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值