当前位置: 首页 > news >正文

【运维高级内容--MySQL】

目录

一、mysql安装

二、MySQL主从复制


一、mysql安装

yum install cmake gcc-c++ openssl-devel ncurses-devel.x86_64 rpcgen.x86_64        #安装依赖性

#在root路径下下载mysql-boost-5.7.44、libtirpc-devel-1.3.3-8.el9_4.x86_64.rpm安装包

yum install libtirpc-devel-1.3.3-8.el9_4.x86_64.rpm -y

tar zxf mysql-boost-5.7.44.tar.gz #解压源码包

cd /root/mysql-5.7.44

#当cmake出错后如果想重新检测,删除 mysql-5.7.44 中 CMakeCache.txt即可

rm -fr CMakeCache.txt                                                                       #删除它可加快make

#源码编译安装MySQL

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \    #指定安装路径
-DMYSQL_DATADIR=/data/mysql \                #指定数据目录
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ #指定套接字文件
-DWITH_INNOBASE_STORAGE_ENGINE=1 \    #指定启用INNODB存储引擎,默认用myisam
-DWITH_EXTRA_CHARSETS=all \                   #扩展字符集
-DDEFAULT_CHARSET=utf8mb4 \                #指定默认字符集
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \                #指定默认校验字符集
-DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/     #指定c++库依赖

make -j2                                                                         #-j2 表示有几个核心就跑几个进程

make install

cd

cd /usr/local/mysql/support-files/

cp mysql.server /etc/init.d/mysqld

cd

vim ~/.bash_profile

# .bash_profile
​
# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fi
​
# User specific environment and startup programs
​
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
​
export PATH

source ~/.bash_profile vim /etc/my.cnf

[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0

cd /usr/local/mysql/

useradd -s /sbin/nologin -M mysql

mkdir /data/mysql -p

chown mysql.mysql -R /data/mysql/

cd

cd /usr/local/mysql/support-files/

cp mysql.server /etc/init.d/mysqld

cd mysqld --user mysql --initialize

#mysql初始密码:

/etc/init.d/mysqld start

chkconfig mysqld on

mysql_secure_installation

Securing the MySQL server deployment.
Enter password for user root: #输入当前密码
The existing password for the user account root has expired. Please set a new
password.
New password: #输入新密码
Re-enter new password: #重复密码
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: no #是否启用密码插件
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no
#是否要重置密码
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No)
: y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

mysql -uroot -pmysql

测试:

二、MySQL主从复制

#172.25.254.110 master

vim /etc/my.cnf

[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
log-bin=mysql-bin
server-id=1

/etc/init.d/mysqld restart

mysql -pmysql

CREATE USER 'repl'@'%' IDENTIFIED BY 'miky';GRANT REPLICATION SLAVE ON *.* TO repl@'%';SHOW MASTER STATUS;

cd /data/mysql/

mysqlbinlog mysql-bin.000001 -vv #查看二进制日志

#172.25.254.120 slave

vim /etc/my.cnf

[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
server-id=2

/etc/init.d/mysqld restart

mysql -pmysql

CHANGE MASTER TOMASTER_HOST='172.25.254.110',MASTER_USER='repl',MASTER_PASSWORD='miky',MASTER_LOG_FILE='mysqlbin.000001',MASTER_LOG_POS=350;
#mysqlbin.000001、350通过在master主机里`SHOW MASTER STATUS查看
start slave;SHOW SLAVE STATUS\G;

注意检查这两个为yes:

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

我碰到的问题:

当重新开启slave后Slave_SQL_Running值会变为NO,可以用以下方法解决:

Slave_SQL_Running: No
1.程序可能在slave上进行了写操作

2.也可能是slave机器重起后,事务回滚造成的.

一般是事务回滚造成的:
解决办法:
mysql> stop slave ;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> start slave ;

在master上删除已创建的库,slave上同步更新库,证明两个机子已经成功同步状态

测试:

#在master上创表

mysql -pmysql

CREATE DATABASE miky;CREATE TABLE miky.userlist (
-> username varchar(20) not null,
-> password varchar(50) not null
-> );
INSERT INTO miky.userlist VALUE ('miky','123');SELECT * FROM miky.userlist;

#在slave上查看数据是否同步过来

SELECT * FROM miky.userlist;

http://www.lryc.cn/news/430524.html

相关文章:

  • 【仿真与实物设计】基于51单片机设计的打地鼠游戏机——程序源码原理图proteus仿真图PCB设计文档演示视频元件清单等(文末工程资料下载)
  • iPhone设备使用技巧:忘记密码的情况下如何解除iOS 18/17屏幕时间
  • 内网渗透的风行者—Yasso
  • Android13 app后台无法启动Abort background activity starts from
  • Day45 | 99.岛屿数量 深搜 广搜 100.岛屿的最大面积
  • css之grid布局(网格布局)
  • 数据可视化大屏模板-美化图表
  • 【与C++的邂逅】--- 类和对象(中)
  • [数据集][目标检测]瞳孔虹膜检测数据集VOC+YOLO格式8768张2类别
  • Day42 | 739. 每日温度 496.下一个更大元素 I 503.下一个更大元素II
  • 运维大规模K8S集群注意事项
  • 供应链系统源码的关键技术是什么?
  • git 修改远程仓库的 URL
  • 使用图数据库 Neo4j 处理对象之间的关系
  • 使用C#的异步和依赖注入实现网络数据存储
  • tomcat日志文件切割
  • Python将Word文档转为PDF
  • 深入浅出链表
  • Linux核心命令入门
  • 腾讯无界微前端框架介绍
  • Linux——网络(2)
  • 结合量子技术解决数据传输安全
  • 【Rust光年纪】提高开发效率:深入了解Rust语言中的数据库客户端和文件处理库
  • 【自动驾驶】控制算法(一)绪论与前期准备
  • CSDN创作一周年总结
  • World of Warcraft [CLASSIC] the Eye of Eternity [EOE] P1-P2
  • 一键翻译全球:多语言支持下的英文翻译工具
  • 水战再起波澜,“怡宝”要下好怎样一盘棋?
  • 使用maven快速生成打包文件3
  • Excel技巧(一)