mysql習慣及主從複製參數設置

mysql 重複數據插入php

 

replace into 跟 insert 功能相似,不一樣點在於:replace into 首先嚐試插入數據到表中, 1. 若是發現表中已經有此行數據(根據主鍵或者惟一索引判斷)則先刪除此行數據,而後插入新的數據。 2. 不然,直接插入新數據。python

要注意的是:插入數據的表必須有主鍵或者是惟一索引!不然的話,replace into 會直接插入數據,這將致使表中出現重複的數據。mysql

replace into t(id, update_time) values(1, now());linux

nginx

replace into t(id, update_time) select 1, now();sql


MySQL replace into 有三種形式:數據庫

1. replace into tbl_name(col_name, ...) values(...)數組

2. replace into tbl_name(col_name, ...) select ...bash

3. replace into tbl_name set col_name=value, ...服務器

/************************ svn linux ***************************/

sudo apt-get install subversion

svn checkout 地址 || svn co svn://遠程地址 ./本地地址 --username 用戶名 --password 密碼

Available subcommands:
add
blame (praise, annotate, ann)
cat
changelist (cl)
checkout (co)
cleanup
commit (ci)
copy (cp)
delete (del, remove, rm)
diff (di)
export
help (?, h)
import
info
list (ls)
lock
log
merge
mergeinfo
mkdir
move (mv, rename, ren)
propdel (pdel, pd)
propedit (pedit, pe)
propget (pget, pg)
proplist (plist, pl)
propset (pset, ps)
resolve
resolved
revert
status (stat, st)
switch (sw)
unlock
update (up)

 

/************************ php數組比較 ***************************/
$q = array(1,2,30,40,50);
$s = array(1,2,4,8,9,9,34,2,12,324,3,34,343);

//共同的部分
$m=array_intersect($q,$s);

//老的數據
$old=array_diff($q,$m);

//新的數據
$new=array_diff($s,$m);

 


// 字段惟一值
ALTER TABLE `kcd_diamond` ADD UNIQUE(`dia_report_no`);

服務器啓動命令:
/usr/sbin/nginx -c /etc/nginx/nginx.conf

// 設定歷史命令的時間


// 查看端口占用狀況
nwtstat -an


//
pclose(popen('/bin/bash /opt/lampp/htdocs/restart.sh','r'));


// 殺掉進程

#!/bin/bash
ps x | grep './wbserver' | grep -v grep | grep -v "'./wbserver'" | awk '{print $1}' | xargs kill -9

從新啓動


/*********************************** MYSQL *****************************************************/


grant all privileges on *.* to user@192.168.3.188 identified by 'pass';
flush privileges;

查看MYSQL數據庫中全部用戶
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

mysqldump -uroot -p kcvdiamond kcd_diamond --where=" dia_sup_id=10020" > /home/diamond.sql


python 資料總結

安裝pip

wget https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz#md5=3823d2343d9f3aaab21cf9c917710196
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-18.3.2.tar.gz#md5=d30c969065bd384266e411c446a86623

// 文件中查找字段

find . -name "*.log" | xargs grep ""

// find . -name "*.log" | xargs grep 192.168.3.75

// 主從複製mysql

 

CHANGE MASTER TO MASTER_HOST='server1',MASTER_USER='repl',MASTER_PASSWORD='p4ssword',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=0;

// 導出數據
/opt/lampp/bin/mysqldump -uroot -p kcvdiamond -l -F > t1.sql

mysqldump -uroot -pIsmond258369 kcvdiamond kcd_diamond --where=" dia_sup_id=10020" > /home/hkgroup.sql

// 導入數據
/opt/lampp/bin/mysql -uroot -p kcvdiamond < t1.sql

replicate-do-table=hrsoft_share.表名# 只複製表名錶

// 複製表數據
insert into dist_systerm_msg (mg_title,mg_cont,mg_type,mg_user,mg_time,mg_ipad_uuid,mg_ipad_token) (select mg_title,mg_cont,mg_type,mg_user,mg_time,mg_ipad_uuid,mg_ipad_token from dist_systerm_msg);

// 嚴格來講如下兩點少用, 逃避錯誤

1.跳過指定數量的事務:
mysql>slave stop;
mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 #跳過一個事務
mysql>slave start

2.修改mysql的配置文件,經過slave_skip_errors參數來跳全部錯誤或指定類型的錯誤
vi /etc/my.cnf
[mysqld]
#slave-skip-errors=1062,1053,1146 #跳過指定error no類型的錯誤
#slave-skip-errors=all #跳過全部錯誤

mysql> show slave status\G;*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.3.136 Master_User: user Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000004 Read_Master_Log_Pos: 2346 Relay_Log_File: localhost-relay-bin.000014 Relay_Log_Pos: 1106 Relay_Master_Log_File: mysql-bin.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: test.t_test Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 2346 Relay_Log_Space: 1283 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: 0Master_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: 1 Master_UUID: 4985efad-79a0-11e5-a6a0-000c29ced604 Master_Info_File: /opt/lampp/var/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

相關文章
相關標籤/搜索