云计算29-------mysql主从数据库(5.7版本)与python的交互及mycat

mysql数据库基本操作:

root@m \~\]# tar -xf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz 解压压缩包 \[root@m \~\]# ls anaconda-ks.cfg mysql-5.7.44-linux-glibc2.12-x86_64 mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz \[root@m \~\]# cp -r mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql \[root@m \~\]# rm -rf /etc/my.cnf \[root@m \~\]# mkdir /usr/local/mysql/mysql-files \[root@m \~\]# useradd -r -s /sbin/nologin mysql \[root@m \~\]# chown mysql:mysql /usr/local/mysql/mysql-files/ \[root@m \~\]# chmod 750 /usr/local/mysql/mysql-files/ 授予权限 \[root@m \~\]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ 进行初始化 2024-08-15T02:37:51.714490Z 0 \[Warning\] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2024-08-15T02:37:51.883374Z 0 \[Warning\] InnoDB: New log files created, LSN=45790 2024-08-15T02:37:51.927026Z 0 \[Warning\] InnoDB: Creating foreign key constraint system tables. 2024-08-15T02:37:51.985501Z 0 \[Warning\] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5e50091b-5aaf-11ef-903e-000c2962cb99. 2024-08-15T02:37:51.986327Z 0 \[Warning\] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2024-08-15T02:37:53.342567Z 0 \[Warning\] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2024-08-15T02:37:53.342586Z 0 \[Warning\] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2024-08-15T02:37:53.344783Z 0 \[Warning\] CA certificate ca.pem is self signed. 2024-08-15T02:37:53.842790Z 1 \[Note\] A temporary password is generated for root@localhost: UW2j.oFipqq= 获得原始密码 \[root@m \~\]# ls anaconda-ks.cfg mysql-5.7.44-linux-glibc2.12-x86_64 mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz \[root@m \~\]# ls /usr/local/mysql/ bin docs lib man README support-files data include LICENSE mysql-files share \[root@m \~\]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql57 \[root@m \~\]# service mysql57 start 启动mysql Starting MySQL.Logging to '/usr/local/mysql/data/m.sql.err'. SUCCESS! 修改配置文件 \[root@m \~\]# vim /usr/local/mysql/my.cnf 主服务器的配置文件 \[mysqld

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

port=3306

log-error=/usr/local/mysql/data/db01-master.err

log-bin=/usr/local/mysql/data/binlog

server-id=10

character_set_server=utf8mb4

root@m \~\]# /usr/local/mysql/bin/mysql -p 开启mysql Enter password: Welcome to the MySQL monitor. Commands end with ; or \\g. Your MySQL connection id is 2 Server version: 5.7.44 Copyright (c) 2000, 2023, 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 'root'; 修改数据库账号 Query OK, 0 rows affected (0.00 sec) mysql\> create user 'chz'@'%' identified by 'chz'; 创建可以连接外部的账号 Query OK, 0 rows affected (0.00 sec) mysql\> grant all on \*.\* to 'chz'@'%'; 授予权限 Query OK, 0 rows affected (0.00 sec) mysql\> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql\> mysql\> create database if not exists test charset utf8mb4 -\> ; Query OK, 1 row affected (0.00 sec) mysql\> use test Database changed mysql\> create table user(id int primary key auto_increment,username varchar(45) not null,password varchar(45) not null); Query OK, 0 rows affected (0.00 sec) mysql\> insert into user (username,password)values("aaa","aaa"); Query OK, 1 row affected (0.01 sec) mysql\> select \* from user -\> ; +----+----------+----------+ \| id \| username \| password \| +----+----------+----------+ \| 1 \| aaa \| aaa \| +----+----------+----------+ 1 row in set (0.00 sec) mysql\> mysql\> select host ,user from mysql.user; +-----------+---------------+ \| host \| user \| +-----------+---------------+ \| % \| chz \| \| % \| slave0 \| \| localhost \| mysql.session \| \| localhost \| mysql.sys \| \| localhost \| root \| +-----------+---------------+ 5 rows in set (0.00 sec) mysql\> update mysql.user set host='%' where user='root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql\> flush privileges; 交互 在python(写成脚本执行) import pymysql conn=pymysql.connect(host="192.168.2.50",port=3306,database="test",user="root",password="root"); cursor=conn.cursor() cursor.execute("create user 'slave2'@'%' identified by 'slave2'") cursor.execute("grant replication slave on \*.\* to 'slave2'@'%'") cursor.execute("flush privileges") cursor.execute("flush tables with read lock") cursor.execute("show master status") print(cursor.fetchall()) isOk=input("slave server ok? y/n") if isOK=='y': cursor.execute("unlock tables") cursor.execute("flush tables with read lock") 锁表 cursor.execute("unlock tables") 取消锁表 mycat \[root@mycat \~\]# ls anaconda-ks.cfg jre-8u191-linux-x64.tar.gz jdk-8u192-linux-x64.tar.gz Mycat-server-1.6.5-release-20180122220033-linux.tar.gz \[root@mycat \~\]# tar -xf jdk-8u192-linux-x64.tar.gz \[root@mycat \~\]# tar -xf Mycat-server-1.6.5-release-20180122220033-linux.tar.gz \[root@mycat \~\]# ls anaconda-ks.cfg jre-8u191-linux-x64.tar.gz jdk1.8.0_192 mycat jdk-8u192-linux-x64.tar.gz Mycat-server-1.6.5-release-20180122220033-linux.tar.gz \[root@mycat \~\]# cp -r jdk1.8.0_192/ /usr/local/jdk \[root@mycat \~\]# cp -r mycat/ /usr/local/ 查看并且配置jdk文件 \[root@mycat \~\]# sed -i '$aexport JAVA_HOME=/usr/local/jdk' /etc/profile \[root@mycat \~\]# source /etc/profile \[root@mycat \~\]# $JAVA_HOME -bash: /usr/local/jdk: 是一个目录 \[root@mycat \~\]# sed -i '$aexport PATH=$PATH:$JAVA_HOME/bin' /etc/profile \[root@mycat \~\]# source /etc/profile \[root@mycat \~\]# $PATH -bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/jdk/BIN:/usr/local/jdk/bin: 没有那个文件或目录 \[root@mycat \~\]# java -version java version "1.8.0_192" Java(TM) SE Runtime Environment (build 1.8.0_192-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode) \[root@mycat \~\]# javac -version javac 1.8.0_192 \[root@mycat \~\]# /usr/local/mycat/bin/mycat console 启动mycat Running Mycat-server... wrapper \| --\> Wrapper Started as Console wrapper \| Launching a JVM... jvm 1 \| Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0 jvm 1 \| Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org jvm 1 \| Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. jvm 1 \| jvm 1 \| log4j:WARN No appenders could be found for logger (io.mycat.memory.MyCatMemory). jvm 1 \| log4j:WARN Please initialize the log4j system properly. jvm 1 \| log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. jvm 1 \| MyCAT Server startup successfully. see logs in logs/mycat.log 启动成功 \[root@mycat \~\]# vim /usr/local/mycat/conf/server.xml ![](https://i-blog.csdnimg.cn/direct/b4343bf511c04c79a54343cb6979f997.png) ![](https://i-blog.csdnimg.cn/direct/9278d5f0b69945ea911c34e39b3a941e.png) \[root@mycat \~\]# vim /usr/local/mycat/conf/server.xml 数据库的账号,数据库的密码,数据库 ![](https://i-blog.csdnimg.cn/direct/8d14d2b6e226491497d50e202bba8780.png) 注释掉 ![](https://i-blog.csdnimg.cn/direct/b392e80246274e92bcaad028c51a1f8b.png) \[root@mycat \~\]# vim /usr/local/mycat/conf/schema.xml 删除前面的,然后修改 ![](https://i-blog.csdnimg.cn/direct/9fc29d87f9214e95aa02656e36b02293.png) ![](https://i-blog.csdnimg.cn/direct/9d3f95d086f6497f95a6a06f0a745a5e.png) ![](https://i-blog.csdnimg.cn/direct/4016113f6c4d4ecf95ffd3b5c4c35b9c.png) \[root@mycat \~\]# /usr/local/mycat/bin/mycat start Starting Mycat-server... \[root@mycat \~\]# netstat -lnput \| grep 8066 测试连接 \[root@client \~\]# cd mysql-8.0.33-linuxglibc2.12-x86_64/ \[root@client mysql-8.0.33-linuxglibc2.12-x86_64\]# cd bin/ \[root@client bin\]# ./mysql -h10.1.1.60 - P8066 -uchz -pchz

相关推荐
nbsaas-boot1 小时前
SQL Server 存储过程开发规范(公司内部模板)
java·服务器·数据库
zgl_200537791 小时前
ZGLanguage 解析SQL数据血缘 之 Python + Echarts 显示SQL结构图
大数据·数据库·数据仓库·hadoop·sql·代码规范·源代码管理
小二·1 小时前
Python Web 开发进阶实战:性能压测与调优 —— Locust + Prometheus + Grafana 构建高并发可观测系统
前端·python·prometheus
acaad2 小时前
Redis下载与安装(Windows)
数据库·redis·缓存
玄〤2 小时前
黑马点评中 VoucherOrderServiceImpl 实现类中的一人一单实现解析(单机部署)
java·数据库·redis·笔记·后端·mybatis·springboot
SunflowerCoder2 小时前
EF Core + PostgreSQL 配置表设计踩坑记录:从 23505 到 ChangeTracker 冲突
数据库·postgresql·c#·efcore
短剑重铸之日2 小时前
《7天学会Redis》Day2 - 深入Redis数据结构与底层实现
数据结构·数据库·redis·后端
七牛云行业应用2 小时前
重构实录:我删了 5 家大模型 SDK,只留了 OpenAI 标准库
python·系统架构·大模型·aigc·deepseek
知乎的哥廷根数学学派2 小时前
基于多模态特征融合和可解释性深度学习的工业压缩机异常分类与预测性维护智能诊断(Python)
网络·人工智能·pytorch·python·深度学习·机器学习·分类
一人の梅雨3 小时前
亚马逊SP-API商品详情接口轻量化实战:合规与商业价值提取指南
python