1. 程式人生 > 實用技巧 >css基礎知識整理

css基礎知識整理

MySQL主從配置

主配置(安裝完mysql的虛擬機器)

基礎配置:

# vi /etc/my.cnf

編輯配置檔案

log_bin=ljblinux1

# These are commonly set, remove the # and set as required.
 basedir = /usr/local/mysql
 datadir = /data/mysql
 port = 3306
 server_id = 31
 socket = /tmp/mysql.sock

# /etc/init.d/mysqld restart

重啟mysqld服務

[root@mysql1 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS
! Starting MySQL. SUCCESS!

# mysqldump -uroot mysql > /tmp/mysql.sql

備份mysql庫(加入環境變數)

[root@mysql1 mysql]# mysqldump -uroot mysql > /tmp/mysql.sql
bash: mysqldump: 未找到命令
[root@mysql1 mysql]# export PATH=$PATH:/usr/local/mysql/bin/
[root@mysql1 mysql]# mysqldump -uroot mysql > /tmp/mysql.sql

# mysql -uroot -e "create database ljb"

建立一個庫儲存資料

# mysql -urootljb< /tmp/mysql.sql

將mysql庫恢復成新建的庫,作為測試資料

資料庫配置

# mysql -uroot

進入資料庫(沒有密碼)

建立用作同步資料的使用者並賦予許可權

mysql> grant replication slave on *.* to 'repl' @192.168.117.33 identified by '123456';
Query OK, 0 rows affected (0.00 sec)

將表鎖住,保持表內資料不變

mysql> flush tables with read lock;
Query OK, 
0 rows affected (0.01 sec)

顯示主機狀態

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| ljblinux1.000001 |   652397 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

從配置(安裝完mysql的虛擬機器)

基礎配置

# vi /etc/my.cnf

編輯配置檔案

 basedir = /usr/local/mysql
 datadir = /data/mysql
 port = 3306
 server_id = 33
 socket = /tmp/mysql.sock

# /etc/init.d/mysqld restart

重啟mysqld服務

[root@mysql2 mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

# scp /tmp/mysql.sql [email protected]:/tmp/

在主上將檔案拷貝到從上,並在從上檢視檔案大小是否一致

[root@mysql1 mysql]# scp /tmp/mysql.sql root@192.168.117.33:/tmp/
The authenticity of host '192.168.117.33 (192.168.117.33)' can't be established.
ECDSA key fingerprint is e7:b9:93:83:70:cb:d6:59:49:f8:56:65:ba:eb:aa:45.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.117.33' (ECDSA) to the list of known hosts.
root@192.168.117.33's password: 
mysql.sql                                         100%  637KB 636.7KB/s   00:00    
[root@mysql1 mysql]# ls -la /tmp/mysql.sql 
-rw-r--r--. 1 root root 651977 12月 31 21:47 /tmp/mysql.sql

# 進入資料庫 create database ljb"

//建立一個和主一樣的庫

[root@mysql2 mysql]# 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> create database ljb;
Query OK, 1 row affected (0.00 sec)

將檔案內容匯入庫

[root@mysql2 mysql]# mysql -uroot ljb < /tmp/mysql.sql

資料庫配置

# mysql -uroot

進入資料庫(沒有密碼)

mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> change master to master_host='192.168.117.31',master_user='repl',master_password='123456',master_log_file='ljblinux1.000001',master_log_pos=652397;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

在主上執行解鎖表

mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

主從同步及相關配置引數

主從同步驗證:

從伺服器上操作並執行命令(防火牆關閉):systemctl stop firewalld

進入資料庫

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.117.31
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: ljblinux1.000001
          Read_Master_Log_Pos: 652397
               Relay_Log_File: mysql2-relay-bin.000002
                Relay_Log_Pos: 283
        Relay_Master_Log_File: ljblinux1.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: 652397
              Relay_Log_Space: 457
              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: 31
                  Master_UUID: 779c463c-4b6d-11eb-995f-000c29cba4d3
             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)

ERROR: 
No query specified

若出現Yes,如上圖狀態,即表示主從配置正常。

其中,主伺服器主要配置引數如下:

binlog-do-db= //僅同步指定的庫

binlog-ignore-db= //忽略指定的庫

從伺服器主要配置引數如下:

replicate_do_db=

replicate_ignore_db=

replicate_do_table=

replicate_ignore_table=

replicate_wild_do_table= //如test.%,支援萬用字元%

replicate_wild_ignore_table=

測試主從

主伺服器上

在主上進入資料庫

mysql> select count(*) from db;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

mysql> truncate table db;
Query OK, 0 rows affected (0.00 sec)

mysql> select count(*) from db;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

從伺服器上

在從上進入資料庫

mysql> select count(*) from db;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)