Implement MySQL a-B

Source: Internet
Author: User

I. environment required
 
The IP addresses of MYSQL services installed on both virtual machines are 192.168.1.1 192.168.1.2.
 
2. The procedure is as follows;
 
Virtual Server 1
 
[Root @ localhost ~] # Yum install mysql-server-y
 
[Root @ localhost ~] # Vim/etc/my. cnf
 
[Mysqld]
 
Datadir =/var/lib/mysql
 
Socket =/var/lib/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. 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 root@192.168.1.2:/tmp/
 
Root@192.168.1.2's password:
 
Full. SQL 100% 412KB 412.4KB/s
 
[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>
 
Virtual Server 2
 
[Root @ localhost ~] # Yum install mysql-server-y
 
[Root @ localhost ~] # Vim/etc/my. cnf
 
[Mysqld]
 
Datadir =/var/lib/mysql
 
Socket =/var/lib/mysql. sock
 
User = mysql
 
Server_id = 2
 
Relay_log =/var/lib/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. pid
 
[Root @ localhost ~] # Service mysqld restar
 
[Root @ localhost ~] # Cd/var/lib/mysql/
 
[Root @ localhost mysql] # ls
 
Ibdata1 ib_logfile0 ib_logfile1 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 = '2017. 168.1.1 ', master_port = 3306, master_user = 'hfj', master_password = '000000', master_log_file = 'binlog. 000003 ', master_log_pos = 376;
 
[Root @ localhost mysql] # mysql
 
Mysql> change master to master_host = '2017. 168.1.1 ', master_port = 3306, master_user = 'hfj', master_password = '000000', 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.