首页 > 其他分享 >实训day29(8.15)

实训day29(8.15)

时间:2024-08-16 16:26:00浏览次数:16  
标签:day29 local mycat 实训 mysql 8.15 mysql57 root usr

一、python管理mysql
1、搭建主mysql


[root@mysql57 ~]# tar -xf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz 
[root@mysql57 ~]# cp -r mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql
[root@mysql57 ~]# rm -rf /etc/my.cnf
[root@mysql57 ~]# mkdir /usr/local/mysql/mysql-files
[root@mysql57 ~]# useradd -r -s /sbin/nologin mysql
[root@mysql57 ~]# chown mysql:mysql /usr/local/mysql/mysql-files/
[root@mysql57 ~]# chown 750 /usr/local/mysql/mysql-files/
[root@mysql57 ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql
[root@mysql57 ~]# ls /usr/local/mysql/
[root@mysql57 ~]# cp /usr/local/mysql/support-files/mysql.server
 /etc/init.d/mysql57
[root@mysql57 ~]# service mysql57 start
[root@mysql57 ~]# /usr/local/mysql/bin/mysql -p
Enter password: 

mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
 
mysql> create user 'blt'@'%' identified by 'blt';
Query OK, 0 rows affected (0.00 sec)
 
mysql> grant all on *.* to 'blt'@'%';
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
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.01 sec)
 
mysql> insert into user (username,password)values("aaa","aaa");
Query OK, 1 row affected (0.02 sec)
 
mysql> select * from user;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
|  1 | aaa      | aaa      |
+----+----------+----------+
1 row in set (0.00 sec)
2、pymysql

[root@client ~]# python3 

>>> import pymysql
>>>conn=pymysql.connect(host="192.168.8.150",port=3306,database="test",user="blt",password="blt");
>>> cursor=conn.cursor()
 

 3、修改root权限

mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

>>>conn=pymysql.connect(host="192.168.8.150",port=3306,database="test",user="root",password="root");
>>> curson=conn.cursor()
>>> cursor.execute("create user 'slave0'@'%' identified by 'slave0'")
0
>>> cursor.execute("grant replication slave on *.* to 'slave0'@'%'")
>>> cursor.execute("flush privileges")
>>> cursor.execute("flush tables with read lock")
0
>>> cursor.execute("unlock tables")
0
>>> cursor.execute("flush tables with read lock")
0
>>> cursor.execute("show master status")
0
>>> print(cursor.fetchall())
()
>>> cursor.execute("show master status")

 4、my.cnf

[root@mysql57 ~]# rm -rf /etc/my.cnf

[root@mysql57 ~]# 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@mysql57 ~]# service mysql57 restart

>>> conn=pymysql.connect(host="192.168.8.150",port=3306,database="test",user="blt",password="blt");
>>> cursor=conn.cursor()
>>> cursor.execute("show master status")
1
>>> print(cursor.fetchall())
(('binlog.000001', 154, '', '', ''),)
>>> cursor.execute("unlock tables")
0

 5、slave数据库

[root@slave57 ~]# tar -xf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz 
[root@slave57 ~]# cp -r mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql
[root@slave57 ~]# ls /usr/local/mysql/
[root@slave57 ~]# mkdir /usr/local/mysql/mysql-files
[root@slave57 ~]# useradd -r -s /sbin/nologin mysql
[root@slave57 ~]# chown mysql:mysql /usr/local/mysql/mysql-files/
[root@slave57 ~]# chmod 750 /usr/local/mysql/mysql-files/

 6、主从同步

[root@mysql57 ~]# rm -rf /usr/local/mysql/data/auto.cnf 
[root@mysql57 ~]# yum -y install rsync

[root@mysql57 ~]# rsync -av /usr/local/mysql/data [email protected]:/usr/local/mysql/

[root@slave57 ~]# yum -y install rsync

[root@slave57 ~]# vim /usr/local/mysql/my.cnf
[root@slave57 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql57
[root@slave57 ~]# sed -i '$aexport PATH=$PATH:/usr/local/mysql/bin' /etc/profile
[root@slave57 ~]# sed -n '$p' /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@slave57 ~]# source /etc/profile
[root@slave57 ~]# chkconfig --add mysql57
[root@slave57 ~]# chkconfig mysql57
[root@slave57 ~]# chkconfig mysql57 on

7、错误

[root@slave57 ~]# service mysql57 start
Starting MySQL.2024-08-15T06:29:37.027747Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/slave57.pid).

[root@slave57 ~]# mkdir /var/log/mariadb
[root@slave57 ~]# touch /var/log/mariadb/mariadb.log
[root@slave57 ~]# chown -R mysql:mysql /var/log/mariadb/
[root@slave57 ~]# service mysql57 start
Starting MySQL. SUCCESS! 

 二、MyCat实现读写分离

1、添加新的虚拟主机,关闭防火墙

[root@mycat ~]# systemctl stop firewalld
[root@mycat ~]# setenforce 0

2、上传jdk和Mycat

[root@mycat ~]# ls

 3、解压并上传到指定位置

[root@mycat ~]# tar -xf Mycat-server-1.6.5-release-20180122220033-linux.tar.gz 
[root@mycat ~]# tar -xf jdk-8u192-linux-x64.tar.gz 
[root@mycat ~]# cp -r jdk1.8.0_192/ /usr/local/jdk
[root@mycat ~]# cp -r mycat/ /usr/local/

 4、查看并且配置jdk文件

[root@mycat ~]# ls /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:/usr/local/jdk/bin: 没有那个文件或目录

[root@mycat ~]# javac -version
javac 1.8.0_192

5、测试启动Mycat 

[root@mycat ~]# /usr/local/mycat/bin/mycat console

 6、配置读写分离

[root@mycat logs]# vim /usr/local/mycat/conf/server.xml 

93         <user name="blt" defaultAccount="true">
94                 <property name="password">blt</property>
95                 <property name="schemas">test</property>
107 <!--
108         <user name="user">
109                 <property name="password">user</property>
110                 <property name="schemas">TESTDB</property>
111                 <property name="readOnly">true</property>
112         </user>
113 -->

[root@mycat logs]# vim /usr/local/mycat/conf/schema.xml  

4         <!-- 1.名称为真实数据库名称,添加一个dataNode-->
5         <schema name="test" dataNode="dn1" checkSQLschema="false" sqlMaxLimit="100">
6         </schema>
7         <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
8                 /> -->
9         <dataNode name="dn1" dataHost="localhost1" database="test" />
20   <writeHost host="hostM1" url="192.168.8.150:3306" user="blt" password="blt">
21            <!-- can have multi read hosts -->
22 <readHost host="hostS2" url="192.168.8. 151:3310" user="blt" password="blt" />
23                 </writeHost>
 
 

7、测试

 

[root@mycat ~]# /usr/local/mycat/bin/mycat start[root@mycat ~]# netstat -lnput | grep 8066
[root@client ~]# cd mysql-5.7.44-linux-glibc2.12-x86_64/
[root@client mysql-5.7.44-linux-glibc2.12-x86_64]# cd bin/
[root@client bin]# ./mysql -h192.168.8.152 -P8066 -ublt -pblt

mysql> show databases;
+--------------------+
| Database           |
+--------------------+              |
| test               |
+--------------------+
1 rows in set (0.00 sec)
 
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> select * from user;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
|  1 | aaa      | aaa      |
+----+----------+----------+
1 row in set (0.00 sec)
 
mysql> show variables like "server_id";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 10    |
+---------------+-------+
1 row in set (0.02 sec)

标签:day29,local,mycat,实训,mysql,8.15,mysql57,root,usr
From: https://blog.csdn.net/weixin_68468644/article/details/141229258

相关文章

  • 2024.8.15随笔
    上午今天自习!写题写爽了!本来说复习顺序为PAM、后缀相关,但是hfu今天在早读完后给我们聊了一些学习的方法、给我们提供了一些学习思路。在思考了一会后,我还是决定不任性去重拾九级难度以上的后缀数组(自动机),而是回过头去复习图论。写了三道紫色的二分图,写爽了!二分图我已经很熟悉......
  • 2024.8.15
    2024.8.15【这雨生于天,死于地,中间的过程就是人生。】Thursday七月十二动态DP(DDP)我们选择从一道模板题讲起[P4719【模板】"动态DP"&动态树分治](P4719[模板]"动态DP"&动态树分治-洛谷|计算机科学教育新生态(luogu.com.cn))【模板】"动态DP"&动态树分治题目描......
  • 云计算实训30——mysql主从复制同步、mysql5.7版本安装配置、python操作mysql数据库、
    一、mysql主从复制及同步1、mysql主从自动开机同步2、配置mysql5.7版本mysql-5.7.44-linux-glibc2.12-x86_64.tar启动服务、登录对数据库进行基本操作3、使用python操纵mysql数据库4、编辑python脚本自动化操纵mysql数据库二、mycat读写分离......
  • 8.15
    不太想写,想起了一些以前的事情,但没鱼可摸了……早起,学姐讲了一些廿四的学风,突然就不想去了,我卷不动啊qwq,据说廿四人中午,体活,体育和副科课都在教室里卷作业,可我只想摆……,想去打羽毛球高一比高二晚去食堂10分钟,因此肯定抢不到炸鸡,甜甜圈,慕斯蛋糕,炸紫薯甜点,鸭腿和自助餐等美味了......
  • 实训日记day29
    MySQL读写分离1、读写分离的目的数据库负载均衡:当数据库请求增多时,单例数据库不能够满足业务需求。需要进行数据库实例的扩容。多台数据库同时相应请求。也就是说需要对数据库的请求,进行负载均衡但是由于数据库服务特殊原因,数据库扩容基本要求为:数据的一致性和完整性......
  • 24.08.15
    day131.C语言本质操作内存命令行参数intmain(intargc,char*argv[])argc:参数的个数argv:参数存放的指针数组intmain(intargc,char*argv[]){inti;for(i=0;i<argc;i++){printf("%s\n",ar......
  • 网络安全实训第二天
    1.业务逻辑漏洞注册一个账号在输入购买数量的输入框中输入-1并提交,然后点击提交订单提交订单后查看余额,发现账号多出6000元,漏洞利用成功2.更改支付金额在选定一个商品之后,使用BP拦截提交订单的请求,并找到价格修改为0查看用户下单界面单价是否为0点击提交订......
  • 网络安全实训第三天
    1文件上传漏洞准备一句话文件wjr.php.png,进入到更换头像的界面,使用BP拦截选择文件的请求拦截到请求后将wjr.phh.png修改为wjr.php,进行转发由上图可以查看到上传目录为网站目录下的upload/avator,查看是否上传成功使用时间戳在线工具获取到上传文件的名称打开......
  • oracle练习2024.08.15
    --1.创建一个名为‘EMP_DETAILS_VIEW’的只读视图,包含各个员工的员工编号、员工名、职位编号、职位名称、部门编号、国家信息和区域信息:createviewemp_details_viewasselect   e.employee_idasemployee_id,  e.first_name||''||e.last_nameasemployee......
  • day44-dynamic programming-part11-8.15
    tasksfortoday:1.1143.最长公共子序列2.1035.不相交的线3.53.最大子序和4.392.判断子序列(编辑距离问题)------------------------------------------------------------------------------1.1143.最长公共子序列300:single,ascending,non-continuity674:s......