• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

实现MySQL的a-b

mysql 搞代码 4年前 (2022-01-09) 27次浏览 已收录 0个评论

一、需要环境 两台虚理机都安装 MYSQL服务 IP分别为192.168.1.1 192.168.1.2 二、以下是个操作步骤; 虚理机一 [

一、需要环境

两台虚理机都安装 MYSQL服务 IP分别为192.168.1.1 192.168.1.2

二、以下是个操作步骤;

虚理机一

[root@localhost ~]# yum install mysql mysql-server -y

[root@localhost ~]# vim /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

server_id = 1

log-bin=binlog

log-bin-index=binlog.index

# Default to using old password format for compatibility with mysql 3.x

# clients (those using the mysqlclient10 compatibility package).

old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;

# to do so, uncomment this line:

# symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

[root@localhost ~]# servicr mysqld start

bash: servicr: command not found

[root@localhost ~]# service mysqld start

[root@localhost ~]# mysql

mysql> quit

Bye

[root@localhost ~]# mysqldump -A -x >/tmp/full.sql

[root@localhost ~]# scp /tmp/full.sql [email protected].1.2:/tmp/

[email protected].1.2’s password:

full.sql 100% 412KB 412.4KB/s 00:00

[root@localhost ~]# mysql

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

Your MySQL connection id is 4

Server version: 5.0.77-log Source distribution

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

mysql> show master status;

+—————+———-+————–+——————+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+—————+———-+————–+——————+

| binlog.000003 | 376 | | |

+—————+———-+————–+——————+

1 row in set (0.00 sec)

mysql>

虚理机二

[root@localhost ~]# yum install mysql mysql-server -y

[root@localhost ~]# vim /etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

server_id = 2

relay_log = /var/lib/mysql/mysql-relay-bin

relay_log_index=/var/lib/mysql/mysql-relay-bin.index

# Default to using old password format for compatibility with mysql 3.x

# clients (those using the mysqlclient10 compatibility package).

old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;

# to do so, uncomment this line:

# symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

[root@localhost ~]# service mysqld restar

[root@localhost ~]# cd /var/lib/mysql/

[root@localhost mysql]# ls

ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock test

[root@localhost mysql]# rm -fr *

[root@localhost mysql]# ls

[root@localhost mysql]# service mysqld restart

[root@localhost mysql]# mysql < /tmp/full.sql

[root@localhost mysql]# mysql> change master to master_host=’192.168.1.1′, master_port=3306, master_user=’hfj’, master_本文来源gaodaimacom搞#代%码@网-password=’123′, master_log_file=’binlog.000003′,master_log_pos=376;

[root@localhost mysql]# mysql

mysql> change master to master_host=’192.168.1.1′, master_port=3306, master_user=’hfj’, master_password=’123′, master_log_file=’binlog.000003′,master_log_pos=376;

Query OK, 0 rows affected (0.04 sec)

mysql> start slave;

Query OK, 0 rows affected (0.00 sec)

mysql> show slavw status;

mysql> show slave status \G;

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

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.1.1

Master_User: hfj

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: binlog.000003

Read_Master_Log_Pos: 376

Relay_Log_File: mysql-relay-bin.000002

Relay_Log_Pos: 232

Relay_Master_Log_File: binlog.000003

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: 376

Relay_Log_Space: 232

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.00 sec)

ERROR:

No query specified

mysql>


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:实现MySQL的a-b

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址