MySQL 8.0.25 二进制安装

1、解压安装包

tar -xf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
mv /usr/local/mysql-8.0.25-linux-glibc2.12-x86_64 /usr/local/mysql-8.0.25

2、创建用户与目录

groupadd mysql
useradd mysql -g mysql
mkdir -p /data/mysql/{data,log}
chown -R mysql.mysql /data/mysql/

3、初始化数据库

/usr/local/mysql-8.0.25/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql-8.0.25 --datadir=/data/mysql/data
#输出如下
2022-09-08T06:48:31.860364Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.25/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 11562
2022-09-08T06:48:31.867586Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-08T06:48:33.123966Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-08T06:48:35.183683Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

4、创建配置文件

vim /etc/my.cnf
[mysqld]
server_id=1
user=mysql
port=3306
basedir=/usr/local/mysql-8.0.25
datadir=/data/mysql/data/
socket=/tmp/mysql.sock
log_error=/data/mysql/log/mysql.log
[mysql]
socket=/tmp/mysql.sock

5、添加环境变量

echo 'export PATH=/usr/local/mysql-8.0.25/bin:$PATH' >> /etc/profile
source /etc/profile

6、创建启动文件

#创建MySQL启动文件
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
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.25/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

7、启动MySQL

#启动MySQL
systemctl daemon-reload && systemctl start mysqld
systemctl enable mysqld

#查看端口
netstat -lutnp |grep mysql
tcp6       0      0 :::33060                :::*                    LISTEN      13523/mysqld        
tcp6       0      0 :::3306                 :::*                    LISTEN      13523/mysqld

8、修改密码

#由于初始化的时候没有设置密码,这里直接进入
root@michael ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 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> alter user root@localhost identified by 'ljl123!@#';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> \q
Bye

#再次输入密码登录
mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.25 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>

9、配置navicat连接

mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> alter user 'root'@'%' identified with mysql_native_password by 'ljl123!@#';
mysql> flush privileges;

#使用Navicat连接即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 MySQL 8.0.25 中设置双主架构,需要按照以下步骤进行操作: 1. 安装 MySQL 8.0.25,确保两个主节点上的 MySQL 版本一致,并且配置文件中包含了以下参数: ``` server-id=1 # 主节点1的ID号 log-bin=mysql-bin # 启用二进制日志 gtid-mode=ON # 启用 GTID enforce-gtid-consistency=ON # 强制 GTID 一致性 binlog-format=ROW # 设置二进制日志格式为 ROW ``` 2. 在两个主节点上创建一个初始同步点,使两个节点上的数据保持一致。可以使用 `mysqldump` 或 `mysqlpump` 工具将一个节点上的数据导出,并在另一个节点上导入。 3. 在两个主节点上启用 Group Replication,这样可以实现自动故障转移和节点恢复。可以在 MySQL 控制台中使用以下命令来启动 Group Replication: ``` SET GLOBAL group_replication_bootstrap_group=ON; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=OFF; ``` 4. 在两个主节点上配置双向同步,这样可以使两个节点之间的数据保持一致。可以使用 MySQL 自带的工具 `mysqlsh` 来实现双向同步,具体命令如下: ``` # 在主节点1上执行 dba.configureLocalInstance(); # 在主节点2上执行 dba.configureLocalInstance(); # 在主节点1上执行 shell.connect('user@主节点2IP'); var cluster = dba.getCluster(); cluster.addInstance({ user: 'user', host: '主节点1IP', password: 'password', port: 3306, sslMode: "REQUIRED", peerUser: 'user', peerPassword: 'password', peerPort: 3306 }); # 在主节点2上执行 shell.connect('user@主节点1IP'); var cluster = dba.getCluster(); cluster.addInstance({ user: 'user', host: '主节点2IP', password: 'password', port: 3306, sslMode: "REQUIRED", peerUser: 'user', peerPassword: 'password', peerPort: 3306 }); ``` 5. 验证双主架构是否设置成功。可以在任意一个主节点上进行数据操作,然后在另一个主节点上查看数据是否同步。也可以模拟主节点故障,然后查看数据是否自动转移到了另一个主节点上。 以上就是在 MySQL 8.0.25 中设置双主架构的基本步骤,具体的实现可能需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值