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

root@mycat \~# vim /usr/local/mycat/conf/server.xml

数据库的账号,数据库的密码,数据库

注释掉

root@mycat \~# vim /usr/local/mycat/conf/schema.xml

删除前面的,然后修改

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

相关推荐
风哥2号2 小时前
数据库教程FGMT02‑生产环境Linux+Oracle19c安装配置与项目实战
linux·数据库·ffmpeg
wuminyu5 小时前
Kafka中sendfile与mmap实现机制解析
java·linux·c语言·jvm·c++
新时代牛马6 小时前
嵌入式网络完整篇:从LwIP/以太网驱动到 Linux netdev 与排障
linux·网络·php
猿与禅6 小时前
Linux(Ubuntu)入门到实战:系统管理、常用命令与权限体系完整指南
linux·ubuntu·apt·进程管理·系统运维·用户权限·vi/vim
前端世界6 小时前
Linux服务器实战:NTP时间同步、SELinux权限与rsyslog日志管理,一次搞懂三大运维问题
linux·运维·服务器
Android系统攻城狮6 小时前
Linux Gstreamer深度解析之gst_audio_converter_new调用流程与实战(二十)
linux·运维·服务器·gstreamer音视频·音视频进阶
H_oRIZoN_11 小时前
Linux入门DAY41(51 单片机 串口与通信协议)
linux·运维·单片机
GeW13 小时前
RHCE备考别瞎学!按这个计划走,30天提高通过率,快速拿证
linux
Escalating_xu13 小时前
【System V 信号量】从 P/V 原语到 Builder 封装:写出可控、可清理的进程互斥组件
java·linux·开发语言·jvm
傲世仙尊13 小时前
System V 进程间通信详解:共享内存、消息队列与信号量(CSDN博客)
linux·开发语言·c++