【MySQL源码部署】

MySQL源码部署

1.下载MySQL

MySQL官网下载地址:MySQL

通过命令查看libc 版本信息,下载对应的压缩包

[root@DB~]#  ldd --version
ldd (GNU libc) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
[root@DB ~]#  

在这里插入图片描述

2.添加用户解压&重命名

# 添加apps 用户 
useradd apps -d /data/apps
# 解压
tar xf mysql-8.0.36-linux-glibc2.28-x86_64.tar.xz -C /data/apps/
# 重命名
cd /data/apps/
mv mysql-8.0.36-linux-glibc2.28-x86_64 mysql

3.设置配置文件

/data/apps/mysql/my.cnf

[mysqld]
# 每台数据库的serverID是不一致的,需要按需修改
server-id=179
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/data/apps/mysql
# 设置mysql数据库的数据的存放目录
datadir=/data/apps/mysql/data
# 设置socket文件
socket=/data/apps/mysql/mysql.sock
# 允许最大连接数
max_connections=3000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
collation_server = utf8_general_ci
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
# 设置sql模式
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
# 设置 错误日志路径
log-error=/data/apps/mysql/logs/error.log
# 日志 
# log=/data/apps/mysql/logs/mysqld.log
# 设置pid
pid-file =/data/apps/mysql/mysql.pid
# 设置时区
default-time-zone='+08:00'
# 先设置免密登录
#$# skip-grant-tables
# 设置忽略大小写
lower_case_table_names=1
# 关闭数据库或表可以存储在my.cnf中指定datadir之外的分区或目录
symbolic-links=0
# 跳过外部锁定 External-locking用于多进程条件下为MyISAM数据表进行锁定
skip-external-locking
# 禁用dns解析
skip-name-resolve
# 设置binlog
log-bin=/data/apps/mysql/data/mysql-bin
# 增加缓冲池
innodb_buffer_pool_size=180G
# 增加日志文件和日志缓冲区
innodb_log_file_size=1G
innodb_log_buffer_size = 64M

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/data/apps/mysql/mysql.sock

[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8
# 设置socket 文件
socket=/data/apps/mysql/mysql.sock

[mysqld_safe]
log-error=/data/apps/mysql/logs/mariadb.log
pid-file=/data/apps/mysql/mariadb.pid

4.设置mysqld服务

# 设置mysql.server文件中46-47行
46 basedir=/data/apps/mysql
47 datadir=/data/apps/mysql/data
# 设置mysqld服务(root用户执行)
cp -ra /data/apps/mysql/support-files/mysql.server /etc/init.d/mysqld

5.初始化

/data/apps/mysql/bin/mysqld  --defaults-file=/data/apps/mysql/my.cnf  --initialize --user=apps --basedir=/data/apps/mysql/  --datadir=/data/apps/mysql/data  --console

6.起服务

service mysqld start

7.设置环境变量

为了避免找不到mysql命令,设置全局环境变量

# 在/etc/profile文件最后追加一下三行
#$# set MySQL Env
export MYSQL_HOME=/data/apps/mysql
export PATH=$PATH:${MYSQL_HOME}/bin

8.设置软连接

ln -s /data/apps/mysql/mysql.sock /tmp/mysql.sock

9.访问数据库

首次初始换完成后在日志文件中可以查看生成的密码

grep generated /data/apps/mysql/logs/error.log

# 查看密码
[apps@DB ~ mysql]#  grep generated  /data/apps/mysql/logs/error.log
2024-04-12T08:30:23.594728Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: r(f_gF!sr1q;
mysql -uroot -p
# 输入查出来的密码
# 修改root密码
alter  user 'root'@'localhost' identified by '123456';
# 刷新权限
flush privileges;
# 查询用户信息
select host,user,authentication_string,plugin,password_expired from mysql.user;

10.设置主从

10.1 主从节点都需要执行

# 创建同步用户
create user repl;
# 修改用户可以远程的主机ip端
update mysql.user set host='192.168.10.%' where user='repl';
# 刷新权限
flush privileges;
#修改用户密码 
alter user 'repl'@'192.168.10.%' identified by '112233';
# 刷新权限
flush privileges;
# 给用户赋予同步的权限
grant replication slave,replication client on *.* to 'repl'@'192.168.10.%';
# 刷新权限
flush privileges;

10.2 主节点执行

# 主执行,查询同步位点
show master status;
[apps@DB-master ~]$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000006 |      157 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> 

10.3 从节点执行

# 从节点直接
change master to master_host='192.168.10.111',master_user='repl',master_password='112233',master_log_file='mysql-bin.000006',master_log_pos=157;
# 启动salve
start slave;
# 查看主从状态
show slave status\G
[apps@DB-slave ~]$ mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 192.168.10.111
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000006
          Read_Master_Log_Pos: 157
               Relay_Log_File: DB-relay-bin.000009
                Relay_Log_Pos: 326
        Relay_Master_Log_File: mysql-bin.000006
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 157
              Relay_Log_Space: 942
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 179
                  Master_UUID: 3b99f581-f582-11ee-970b-fa163e0c49ed
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set, 1 warning (0.01 sec)

mysql> 

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值