[root@hanfeng ~]# ls /usr/local/mysql bin data include man my-new.cnf README share support-files COPYING docs lib my.cnf mysql-test scripts sql-bench [root@hanfeng ~]#
在 /etc/my.cnf 文件中 定義 datadir=/data/mysql 定義 socket=/tmp/mysql.sock
vim /etc/init.d/mysqld //對如下兩行進行指定路徑 指定basedir的路徑 /usr/local/mysql 指定datadir的路徑 /data/mysql
[root@hanfeng ~]# vim /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] server_id = 130 log_bin=hf123 # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M 保存退出
[root@hanfeng ~]# /etc/init.d/mysqld restart Shutting down MySQL.... SUCCESS! Starting MySQL.. SUCCESS! [root@hanfeng ~]#
[root@hanfeng ~]# ls -lt /data/mysql/ 總用量 110728 -rw-rw----. 1 mysql mysql 50331648 1月 19 23:35 ib_logfile0 -rw-rw----. 1 mysql mysql 12582912 1月 19 23:35 ibdata1 -rw-rw----. 1 mysql mysql 104317 1月 19 23:35 hanfeng.err -rw-rw----. 1 mysql mysql 5 1月 19 23:35 hanfeng.pid -rw-rw----. 1 mysql mysql 15 1月 19 23:35 hf123.index -rw-rw----. 1 mysql mysql 120 1月 19 23:35 hf123.000001 drwx------. 2 mysql mysql 4096 1月 19 20:58 zrlog -rw-rw----. 1 mysql mysql 56 1月 2 22:41 auto.cnf drwx------. 2 mysql mysql 4096 1月 2 22:28 mysql drwx------. 2 mysql mysql 4096 1月 2 22:28 performance_schema -rw-rw----. 1 mysql mysql 50331648 1月 2 22:28 ib_logfile1 drwx------. 2 mysql mysql 6 1月 2 22:26 test [root@hanfeng ~]#
[root@hanfeng ~]# mysqldump -uroot -phanfeng zrlog > /tmp/zrlog.sql Warning: Using a password on the command line interface can be insecure. [root@hanfeng ~]#
[root@hanfeng ~]# mysql -uroot -phanfeng -e "create database han" Warning: Using a password on the command line interface can be insecure. [root@hanfeng ~]#
[root@hanfeng ~]# mysql -uroot -phanfeng han < /tmp/zrlog.sql Warning: Using a password on the command line interface can be insecure. [root@hanfeng ~]#
[root@hanfeng ~]# ls -lt /data/mysql/ 總用量 110740 -rw-rw----. 1 mysql mysql 50331648 1月 19 23:40 ib_logfile0 -rw-rw----. 1 mysql mysql 12582912 1月 19 23:40 ibdata1 -rw-rw----. 1 mysql mysql 10337 1月 19 23:40 hf123.000001 drwx------. 2 mysql mysql 4096 1月 19 23:40 han -rw-rw----. 1 mysql mysql 104317 1月 19 23:35 hanfeng.err -rw-rw----. 1 mysql mysql 5 1月 19 23:35 hanfeng.pid -rw-rw----. 1 mysql mysql 15 1月 19 23:35 hf123.index drwx------. 2 mysql mysql 4096 1月 19 20:58 zrlog -rw-rw----. 1 mysql mysql 56 1月 2 22:41 auto.cnf drwx------. 2 mysql mysql 4096 1月 2 22:28 mysql drwx------. 2 mysql mysql 4096 1月 2 22:28 performance_schema -rw-rw----. 1 mysql mysql 50331648 1月 2 22:28 ib_logfile1 drwx------. 2 mysql mysql 6 1月 2 22:26 test [root@hanfeng ~]#
[root@hanfeng ~]# mysql -uroot -phanfeng Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 194 Server version: 5.6.35-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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>
mysql> grant replication slave on *.* to 'repl'@'192.168.202.131' identified by 'hanfeng'; Query OK, 0 rows affected (0.00 sec) mysql>
mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql>
mysql> show master status; +--------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +--------------+----------+--------------+------------------+-------------------+ | hf123.000001 | 10549 | | | | +--------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> quit Bye
[root@hanfeng ~]# ls /data/mysql auto.cnf hanfeng.err hf123.000001 ibdata1 ib_logfile1 performance_schema zrlog han hanfeng.pid hf123.index ib_logfile0 mysql test [root@hanfeng ~]#
[root@hanfeng ~]# mysqldump -uroot -phanfeng test > /tmp/test.sql Warning: Using a password on the command line interface can be insecure. [root@hanfeng ~]#
[root@hanfeng ~]# ls /tmp/*sql /tmp/test.sql /tmp/zrlog.sql [root@hanfeng ~]#
[root@hf-01 ~]# vim /etc/my.cnf [mysqld] datadir=/data/mysql socket=/tmp/mysql.sock server-id=131 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] # log-error=/var/log/mariadb/mariadb.log # pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # # !includedir /etc/my.cnf.d join_buffer_size = 128M sort_buffer_size = 2M read_rnd_buffer_size = 2M 保存退出
[root@hf-01 ~]# /etc/init.d/mysqld restart Shutting down MySQL.... SUCCESS! Starting MySQL... SUCCESS! [root@hf-01 ~]#
[root@hf-01 ~]# ls /data/mysql aria_log.00000001 hf-01.err ibdata1 localhost.localdomain.err performance_schema aria_log_control hf-01.pid ib_logfile0 multi-master.info test auto.cnf ib_buffer_pool ib_logfile1 mysql
[root@hf-01 ~]# scp 192.168.202.130:/tmp/*.sql /tmp/ root@192.168.74.129's password: _oo0oo_ [root@hf-01 ~]#
- 解決方法: - 將主機器的裏的開機啓動腳本關閉vi .bashrc配置文件文件中註釋掉腳本,再來拷貝數據到從機器上,會發現成功
[root@hf-01 ~]# scp 192.168.202.130:/tmp/*.sql /tmp/ The authenticity of host '192.168.202.130 (192.168.202.130)' can't be established. ECDSA key fingerprint is 25:ce:a9:96:36:88:84:ab:4f:7e:80:a3:e7:36:2c:9f. Are you sure you want to continue connecting (yes/no)? yes\ Warning: Permanently added '192.168.202.130' (ECDSA) to the list of known hosts. root@192.168.202.130's password: test.sql 100% 1258 1.2KB/s 00:00 zrlog.sql 100% 10KB 9.8KB/s 00:00 [root@hf-01 ~]#
[root@hf-01 ~]# mysql -uroot -bash: mysql: 未找到命令 [root@hf-01 ~]#
[root@hf-01 ~]# alias 'mysql=/usr/local/mysql/bin/mysql' [root@hf-01 ~]# alias 'mysqldump=/usr/local/mysql/bin/mysqldump'
[root@hf-01 ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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>
mysql> create database zrlog; Query OK, 1 row affected (0.00 sec) mysql> create database test1; Query OK, 1 row affected (0.00 sec) mysql> quit Bye 退出數據庫
[root@hf-01 ~]# mysql -uroot test < /tmp/test.sql [root@hf-01 ~]# mysql -uroot zrlog < /tmp/zrlog.sql [root@hf-01 ~]#
[root@hf-01 ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.6.35 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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>
mysql> stop slave; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>
mysql> change master to master_host='192.168.202.130', master_user='repl', master_password='hanfeng', master_log_file='hf123.000001', master_log_pos=10549; Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> start slave; Query OK, 0 rows affected (0.01 sec) mysql>
查看slave配置html
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.202.130 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: hf123.000001 Read_Master_Log_Pos: 10549 Relay_Log_File: hf-01-relay-bin.000002 Relay_Log_Pos: 279 Relay_Master_Log_File: hf123.000001 Slave_IO_Running: Yes //檢查是否爲Yes Slave_SQL_Running: Yes //檢查是否爲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: 10549 Relay_Log_Space: 452 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 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 130 Master_UUID: fd146e3b-efca-11e7-b3d6-000c29ff458f Master_Info_File: /data/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec) mysql>
[root@hf-01 mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 15 Server version: 5.6.35-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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> unlock table; Query OK, 0 rows affected (0.00 sec)