分类目录归档:Knowledge Base

Python在Windows下激活Venv环境

  • 起因

最近为公司写python程序需要打包为exe文件夹,因此创建Venv环境以免生成的exe文件过大。

  • 解决办法
  1. 进入需要生成Venv环境的文件夹
  2. 输入如下命令:“python -m venv myvenv”
  3. 进入生成的文件夹中的Scripts文件夹
  4. 输入activate激活虚拟环境
  5. 输入deactivate退出虚拟环境

CentOS7.9安装MySQL8.0

  • 关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  • 获取并安装MySQL8.0源
wget http://repo.mysql.com/mysql80-community-release-el7.rpm
rpm -ivh mysql80-community-release-el7.rpm
安装rpm完成验证
  • 关闭mysql-community.repo中gpg校验
cd /etc/yum.repo
vi mysql-community.repo
gpgcheck=0
修改gpgcheck=0
  • 安装MySQL8.0
yum install mysql-server
  • 启动MySQL8.0设置开机自启动
systemctl start mysqld
systemctl status mysqld
systemctl enable mysqld
  • MySQL初始化设置
mysqld --initialize

#获取MySQL临时密码
grep 'temporary password' /var/log/mysqld.log

#修改MySQL密码<
alter user 'root'@'localhost' identified by 'P@ssw0rd';

use mysql;
#修改root账户权限
update user set host = '%' where user = 'root';

#刷新权限<br>flush privileges;

CentOS8切换阿里镜像源

  • 问题

在CentOS8中使用yum时出现错误,问题如下:

Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
  • 原因

在2022年1月31日,CentOS团队终于从官方镜像中移除CentOS 8的所有包。

CentOS 8已于2021年12月31日寿终正寝,但软件包仍在官方镜像上保留了一段时间。现在他们被转移到https://vault.centos.org

  • 切换阿里源方法

1.备份源文件

cd /etc/yum.repos.d/ && mkdir backup && mv *repo backup/

2.下载阿里源文件

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

3.更新源文件内地址

sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*
sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*

4.生成缓存

yum clean all && yum makecache

MySQL主从复制模式原理

近期去面试,被问到对于MySQL主从复制模式的原理,回答不甚理想,因此留下此贴进行记录。

  • 原理概述

  1. Master服务器将数据变更的记录写入二进制binlog日志中;
  2. Slave服务器定期对Master服务器的binlog日志进行探测,若发现改变,则创建一个I/O线程请求Master二进制事件,并写入relay log中;
  3. Slave服务器创建一个SQL线程,从relay log中读取内容,从Exec_Master_Log_Pos位置开始执行读取到的数据库更新事件,并将更新内容写入到数据库中。
  • 主从流程图

继续阅读