linux、mysql日常工作备忘录

Mysql

==mysql8远程授权访问==========================================
use mysql;
mysql8不再允许直接对root用户授权远程访问,需要新建一个用户。
CREATE USER 'root'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '111111';

mysql8设置安全策略============================================
validate_password.length=6
validate_password.mixed_case_count=0
validate_password.number_count=0
validate_password.policy=LOW
validate_password.special_char_count=0

mysql8数据备份============================================
mysqldump -u your_username -p your_password your_database > backup_file.sql
mysqldump -u your_username -p your_password --no-data your_database > backup_file.sql
mysqldump -u your_username -p your_password --add-drop-table your_database > backup_file.sql
mysqldump -u your_username -p your_password --no-create-db your_database > backup_file.sql

mysql8安装=================================================
依赖库:
mysql-community-server-core依赖        libmecab2、libnuma1、libaio1、psmisc


1.安装:dpkg -i mysql-common_8.0.34-1debian11_amd64.deb
2.安装:dpkg -i mysql-community-client-plugins_8.0.34-1debian11_amd64.deb
3.安装:dpkg -i mysql-community-client-core_8.0.34-1debian11_amd64.deb
4.安装:dpkg -i mysql-community-client_8.0.34-1debian11_amd64.deb
5.安装:dpkg -i mysql-client_8.0.34-1debian11_amd64.deb
6.安装:dpkg -i mysql-community-server-core_8.0.34-1debian11_amd64.deb
8.安装:dpkg -i mysql-community-server_8.0.34-1debian11_amd64.deb


mysql优化================================================
[mysqld]

# 设置基本参数
port = 3306
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql

# 优化InnoDB存储引擎
innodb_buffer_pool_size = 2G       # InnoDB缓冲池大小,占用可用内存的一半
innodb_log_file_size = 512M        # InnoDB日志文件大小,根据实际写入量进行调整
innodb_flush_log_at_trx_commit = 1 # 每次事务提交时都将日志强制写入磁盘,确保事务的持久性
innodb_flush_method = O_DIRECT     # 使用直接IO提高性能
innodb_file_per_table = 1          # 每个表单独存储,避免数据碎片
innodb_io_capacity = 200          # InnoDB IO容量,根据磁盘性能进行调整
innodb_io_capacity_max = 400      # InnoDB IO容量最大值,根据磁盘性能进行调整

# 限制二进制日志大小,避免占用过多磁盘空间
max_binlog_size = 100M

# 限制错误日志大小,避免占用过多磁盘空间
log_error = /var/log/mysql/error.log

# 优化查询缓存
query_cache_type = 0             # 禁用查询缓存       mysql8已经移除这两个选项
query_cache_size = 0             # 禁用查询缓存

# 设置连接和线程相关参数
max_connections = 200            # 最大连接数,根据并发连接数进行调整
thread_cache_size = 16           # 线程缓存大小,根据并发连接数进行调整

# 优化临时表和堆表
tmp_table_size = 64M            # 临时表大小
max_heap_table_size = 64M       # 最大堆表大小

# 设置日志和慢查询日志
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2

Linux

================网络=====================================
/etc/sysctl.conf
net.ipv4.tcp_fin_timeout = 30            //socket本端关闭,停留在TIME_WAIT状态下的时间,单位秒
net.ipv4.tcp_keepalive_time = 1200      //tcp链接探活频率,单位秒,每隔一段时间探测一次
net.ipv4.route.gc_timeout = 100
net.ipv4.ip_local_port_range = 1024 65000   //发起链接时分配的端口范围
net.ipv4.tcp_tw_reuse = 1           //表示开启重用,允许TIME-wAIT sockets重新用于新的TCP链接,默认值为0
net.ipv4.tcp_tw_recycle = 1         //快速回收socket
net.ipv4.tcp_syn_retries = 1        //外向syn握手重试次数
net.ipv4.tcp_synack_retries = 1     //为了打开对端的连接,内核需要发送一个 SYN 并附带一个回应前面一个 SYN 的 ACK。也就是所谓三次握手中的第二次握手。syn-ack握手状态重试次数,默认5,遭受SYN Flood [(SYN洪水) 是种典型的DoS (Denial of Service,拒绝服务)]攻击时改为1或2
net.core.somaxconn=32768        //该选项默认值是128,这个参数用于调节系统同时发起的TCP连接数
net.ipv4.tcp_max_syn_backlog = 262144   //表示SYN队列的长度,默认为1024,建议加大队列的长度,为8182或更多,这样可以容纳更多等待链接的网络连接数,
net.core.netdev_max_backlog = 262144    // 网卡设备将请求放入队列的长度,表示当每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许发送到队列的数据包最大数,
net.core.somaxconn = 262144         //如果 backlog 大于内核参数 net.core.somaxconn,则以 net.core.somaxconn 为准,
net.ipv4.tcp_max_orphans = 3276800      //用于设定系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上,如果超过这个数值,孤立链接将立即被复位并打印出警号信息,这个限制只是为了防止简单的DoS攻击,不能过分依靠这个限制甚至人为减小这个值,更多的情况是增加这个值
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_tw_buckets = 30000 //表示系统同时保持 TIME_WAIT 套接字的最大数量,如果超过这个数值,TIME_WAIT 套接字将立刻被清除并打印警告信息,1st低于此值,TCP没有内存压力,2nd进入内存压力阶段,3rdTCP拒绝分配socket(单位:内存页)
net.ipv4.tcp_window_scaling = 1     //开启窗口缩放功能,要支持超过64KB的TCP窗口,必须启用该值,TCP连接双方都启用时才生效
net.core.rmem_max = 5242880     //表示套接字接收缓冲区的内存最大值
net.core.wmem_max = 5242880     //表示套接字发送缓冲区大小的最大值,会覆盖 net.ipv4.tcp_wmem的MAX值
net.ipv4.tcp_rmem = 16384 32768 5242880         //接受缓冲的大小:MIN,DEFAULT,MAX。即TCP读取缓冲区,单位为字节byte
net.ipv4.tcp_wmem = 16384 32768 5242880         //socket的发送缓存区分配的MIN,DEFAULT,MAX。发送缓冲区,单位是字节byte
net.ipv4.tcp_mem = 2097152 3145728 4194304      // 1低于此值,TCP没有内存压力,2在此值下,进入内存压力阶段,3高于此值,TCP拒绝分配socket.内存单位是页,1页等于4096字节,1 Page = 4096 Bytes
net.ipv4.tcp_timestamps = 0     //禁用时间戳,时间戳可以避免序列号的卷绕
net.ipv4.tcp_sack = 1       //定义SYN重试次数
net.ipv4.ip_conntrack_max = 20000   //单独一个进程最多可以同时建立20000多个TCP客户端连接
=====================文件数量=================================
/etc/security/limits.conf
soft nproc 65535
hard nproc 65535
soft nofile 65535
hard nofile 65535

Debian

apt代理设置

在目录/etc/apt/apt.conf.d下创建一个xxxx.conf的文件,并添加以下内容

Acquire::http::proxy "http://ip:端口/";
Acquire::https::proxy "http://ip:端口/";

bookworm 官方源

deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware

deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware

deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware

deb http://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware

bullseye国内镜像源

deb https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free

deb https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free

deb https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free

deb https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

毒丐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值