mysql master-slave_mysql 同步 master-slave

mysql 同步 master-slave

这么一个简单问题,在ubuntu居然搞了两天,终于搞定了。

中途出了点问题,搞的郁闷一天的问题就是 change master  语句,好了下面就开始讲正题吧。

linux OS: ubuntu server 8.04.1

software: mysql5.0.51

mysql1  : 192.168.6.4    //master

mysql2  : 192.168.6.5    //slave

安装步骤

1. 分别在两台机器上安装mysql-server

shell > apt-get install mysql-server

2.修改 mysql1 master 的配置文件

vim /etc/mysql/my.cnf

找到 bind-address = 127.0.0.1

改为 bind-address = 0.0.0.0

找到

#server-id               = 1

#log_bin                 = /var/log/mysql/mysql-bin.log

去掉 注释符号

server-id               = 1

log_bin                 = /var/log/mysql/mysql-bin.log

default-character-set   = utf8     #新加上的为了保持编码一至防止出错

3.改好后保存退出,然后建立一个slave服务器的用户账号

root@msyql1:/# mysql -uroot -p

mysql>  grant replication slave,replication client on *.* to ludy@'192.168.6.5' identified by 'ypmwbg';

mysql >  grant replication slave on *.* to ludy@192.168.6.5 identified by 'ypmwbg';     //给予权限

到这里要注意了,我的两台数据库都是空的.

重启mysql服务

4.修改 mysql2 服务器slave的 my.cnf配置文件

找到 bind-address            = 127.0.0.1

替换 bind-address            = 0.0.0.0

找到

#server-id               = 1

#log_bin                 = /var/log/mysql/mysql-bin.log

把 注释符号去掉 改为如下

server-id               = 2

master-host             = 192.168.6.4

master-user             = ludy

master-password         = ypmwbg

master-port             = 3306

log_bin                 = /var/log/mysql/mysql-bin.log

log-slave-updates

skip-slave-start

配置完后 重新启动mysql

然后进入 mysql1 master 服务器

root@msyql:~# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.0.51a-3ubuntu5.4-log (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000001 |      98  |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

记录下来以后 进入 mysql2 slave mysql

root@msyql2:~# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 5.0.51a-3ubuntu5.4-log (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>  change master to master_log_file='mysql-bin.000001', master_log_pos=98;

//这个地方就是记录下来的 mysql1 master 的数据

mysql > start slave;  //启动slave 服务

mysql > show slave status\G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.6.4

Master_User: ludy

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000001

Read_Master_Log_Pos: 181

Relay_Log_File: mysqld-relay-bin.000003

Relay_Log_Pos: 235

Relay_Master_Log_File: mysql-bin.000001

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 181

Relay_Log_Space: 235

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

1 row in set (0.01 sec)

哈哈      Slave_IO_Running: Yes

Slave_SQL_Running: Yes

说明启动成功

然后在 master 新建 一个数据库看看

root@msyq1l:/# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.0.51a-3ubuntu5.4-log (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database chenggong;

Query OK, 1 row affected (0.00 sec)

在 salve 查看看是否同步

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| chenggong          |   //同步了哈哈 ~

| mysql              |

| test               |

+--------------------+

4 rows in set (0.01 sec)

好了就写这么多,如果你作 master-slave 的时候 你的master 数据里有数据那么

你必须 在  我写的 第三步与第四步中加入一下步骤:

接 上文 第三步进入master数据库的Mysql控制台执行

mysql >FLUSH TABLES WITH READ LOCK;   //锁表

然后从新打开一个 终端 拷贝 master 的所有的数据到 slave 服务器覆盖

读取  master 二进制文件与偏移量

mysql > show master status;

同样 要记录下 file 与 position 的值

然后解锁

mysql > unlock tables;

©著作权归作者所有:来自51CTO博客作者Deidara的原创作品,如需转载,请注明出处,否则将追究法律责任

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于LSTM的财务因子预测选股模型LSTM (Long Short-Term Memory) 是一种特殊的循环神经网络(RNN)架构,用于处理具有长期依赖关系的序列数据。传统的RNN在处理长序列时往往会遇到梯度消失或梯度爆炸的问题,导致无法有效地捕捉长期依赖。LSTM通过引入门控机制(Gating Mechanism)和记忆单元(Memory Cell)来克服这些问题。 以下是LSTM的基本结构和主要组件: 记忆单元(Memory Cell):记忆单元是LSTM的核心,用于存储长期信息。它像一个传送带一样,在整个链上运行,只有一些小的线性交互。信息很容易地在其上保持不变。 输入门(Input Gate):输入门决定了哪些新的信息会被加入到记忆单元中。它由当前时刻的输入和上一时刻的隐藏状态共同决定。 遗忘门(Forget Gate):遗忘门决定了哪些信息会从记忆单元中被丢弃或遗忘。它也由当前时刻的输入和上一时刻的隐藏状态共同决定。 输出门(Output Gate):输出门决定了哪些信息会从记忆单元中输出到当前时刻的隐藏状态中。同样地,它也由当前时刻的输入和上一时刻的隐藏状态共同决定。 LSTM的计算过程可以大致描述为: 通过遗忘门决定从记忆单元中丢弃哪些信息。 通过输入门决定哪些新的信息会被加入到记忆单元中。 更新记忆单元的状态。 通过输出门决定哪些信息会从记忆单元中输出到当前时刻的隐藏状态中。 由于LSTM能够有效地处理长期依赖关系,它在许多序列建模任务中都取得了很好的效果,如语音识别、文本生成、机器翻译、时序预测等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值