2022年5月25日 星期三

Slow MySql Server Performance - What and How to check?

0

Slow MySql Server Performance - What and How to check?


Log slow queries- If your system has a ton of queries, it gets tougher to find out which queries are slowing your system. MySQL provides a tool to log slow queries for further analysis https://dev.mysql.com/doc/refman/8.0/en/slow-query-log.html


EXPLAIN Extended command shows details about your queries when your have no idea what is happening https://dev.mysql.com/doc/refman/8.0/en/explain-extended.html


To speed up your queries use Index - A good practice is add index by seeing which fields are in the WHERE clause add index for them. Also if you are retrieving all fields from a table, the query gets slower by fetching all data from disk. In SELECT query you should specify which fields you need to bring instead to bring them all with *

Not 
SELECT * FORM xTable ;

Yes
SELECT ID, Name, Addr FORM xTable ; 

Make use of Query Cache https://dev.mysql.com/doc/refman/5.7/en/query-cache-configuration.html

SHOW VARIABLES LIKE 'have_query_cache';

Make sure that your MySQL server configuration file options are optimized according to your hardware https://dev.mysql.com/doc/refman/8.0/en/option-files.html


Make sure that you are using optimized data types while creating a table structure For example "Comments" fields has size of 256 characters, reply it to MYSQL with a field with type VARCHAR(256) instead of using TEXT. The query will be much faster.



rocedure_Analyse() can help you in finding optimal data types:

http://www.mysqlperformanceblog.com/2009/03/23/procedure-analyse/

http://dev.mysql.com/doc/refman/5.0/en/procedure-analyse.html

http://dba.stackexchange.com/questions/53229/slow-mysql-server-performance-what-and-how-to-check

2022年5月20日 星期五

正則表達式 (regex) 各程式語言使用方法 (part 5)

0

#Java

public class RegexTestStrings {
  public static final String EXAMPLE_TEST = "This is my small example "
      + "string which I'm going to " + "use for pattern matching.";

  public static void main(String[] args) {
    System.out.println(EXAMPLE_TEST.matches("\\w.*"));
    String[] splitString = (EXAMPLE_TEST.split("\\s+"));
    System.out.println(splitString.length);// should be 14
    for (String string : splitString) {
      System.out.println(string);
    }
    // replace all whitespace with tabs
    System.out.println(EXAMPLE_TEST.replaceAll("\\s+", "\t"));
  }
} 


#PHP

$str = 'a1234';
if (preg_match("/^[a-zA-Z0-9]{4,16}$/", $str)) {
    echo "驗證成功";
} else {
    echo "驗證失敗";
}

#perl 
print $str = "a1234" =~ m:^[a-zA-Z0-9]{4,16}$: ? "COMFIRM" : "FAILED";




正則表達式 (regex) 範例 (part 4)

0



只能輸入1個數字 
表達式 \d$
描述 匹配一個數字
匹配的例子 0,1,2,3
不匹配的例子

只能輸入n個數字  
表達式\d{8}
描述匹配8個數字
匹配的例子12345678,22223334,12344321
不匹配的例子

只能輸入至少n個數字 
表達式\d{8,}
描述匹配最少n個數字
匹配的例子12345678,123456789,12344321
不匹配的例子

只能輸入m到n個數字 
表達式\d{7,8}$
描述匹配m到n個數字
匹配的例子12345678,1234567
不匹配的例子123456,123456789

只能輸入數字  
表達式[0-9]*$
描述匹配任意個數字
匹配的例子12345678,1234567
不匹配的例子E,

只能輸入某個區間數字  
表達式[12-15]$
描述匹配某個區間的數字
匹配的例子12,13,14,15
不匹配的例子

只能輸入0和非0打頭的數字  
表達式(0|[1-9][0-9]*)$
描述可以為0,第一個數字不能為0,數字中可以有0
匹配的例子12,10,101,100
不匹配的例子01,

只能輸入實數  
表達式[-+]?\d+(\.\d+)?$
描述匹配實數
匹配的例子18,+3.14,-9.90
不匹配的例子.6,33s,67-99

只能輸入n位小數的正實數  
表達式^[0-9]+(.[0-9]{n})?$以^[0-9]+(.[0-9]{2})?$為例
描述匹配n位小數的正實數
匹配的例子2.22
不匹配的例子2.222,-2.22,

只能輸入mn位小數的正實數  
表達式^[0-9]+(.[0-9]{m,n})?$以^[0-9]+(.[0-9]{1,2})?$為例
描述匹配m到n位小數的正實數
匹配的例子2.22,2.2
不匹配的例子2.222,-2.2222,

只能輸入非0的正整數  
表達式^/+?[1-9][0-9]*$
描述匹配非0的正整數
匹配的例子2,23,234
不匹配的例子0,-4,

只能輸入非0的負整數 
表達式^/-[1-9][0-9]*$
描述匹配非0的負整數
匹配的例子-2,-23,-234
不匹配的例子0,4,

只能輸入n個字符 
表達式^.{n}$ 以^.{4}$為例
描述匹配n個字符,注意漢字只算1個字符
匹配的例子1234,12we,123清,清清月兒
不匹配的例子0,123,123www,

只能輸入英文字符 
表達式^.[A-Za-z]+$為例
描述匹配英文字符,大小寫任意
匹配的例子Asp,WWW,
不匹配的例子0,123,123www,

只能輸入大寫英文字符 
表達式^.[AZ]+$為例
描述匹配英文大寫字符
匹配的例子NET,WWW,
不匹配的例子0,123,123www,

只能輸入小寫英文字符 
表達式^.[az]+$為例
描述匹配英文大寫字符
匹配的例子asp,csdn
不匹配的例子0,NET,WWW,

只能輸入英文字符+數字 
表達式^.[A-Za-z0-9]+$為例
描述匹配英文字符+數字
匹配的例子1Asp,W1W1W,
不匹配的例子0,123,123,www,

只能輸入英文字符/數字/下劃線 
表達式^/w+$為例
描述匹配英文字符或數字或下劃線
匹配的例子1Asp,WWW,12,1_w
不匹配的例子3#,2-4,w#$,

密碼舉例 
表達式^.[a-zA-Z] /w{m,n}$
描述匹配英文字符開頭的mn位字符且只能數字字母或下劃線
匹配的例子
不匹配的例子

驗證首字母大寫 
表達式/b[^/Wa-z0-9_][^/WA-Z0-9_]*/b
描述首字母只能大寫
匹配的例子Asp,Net
不匹配的例子

驗證網址(帶?id=中文)VS.NET2005無此功能 
表達式
^http:////([/w-]+(/.[/w-]+)+(//[/w- .///?%&=/u4e00-/u9fa5]*)?) ?$
描述驗證帶?id=中文
匹配的例子,
http://blog.csdn.net?id=清清月兒
不匹配的例子

驗證漢字 
表達式^[/u4e00-/u9fa5]{0,}$
描述只能漢字
匹配的例子清清月兒
不匹配的例子

驗證QQ號 
表達式[0-9]{5,9}
描述5-9位的QQ號
匹配的例子10000,123456
不匹配的例子10000w,

驗證電子郵件(驗證MSN號一樣)
表達式/w+([-+.´]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
描述注意MSN用非hotmail.com郵箱也可以
匹配的例子aaa@msn.com
不匹配的例子111@1.

驗證身份證號(粗驗,最好服務器端調類庫再細驗證) 
表達式^[1-9]([0-9]{16}|[0-9]{13})[xX0-9]$
描述
匹配的例子15或者18位的身份證號,支持帶X的
不匹配的例子

驗證手機號(包含159,不包含小靈通) 
表達式^13[0-9]{1}[0-9]{8}|^15[9]{1}[0-9]{8}
描述包含159的手機號130-139
匹配的例子139XXXXXXXX
不匹配的例子140XXXXXXXX,

驗證電話號碼號
表達式(不完美方案一((/(/d{3}/)|/d{3}-)|(/(/d{4}/)|/d{4}-))?(/d{8}|/ d{7})
方案二(^[0-9]{3,4}/-[0-9]{3,8}$)|(^[0-9]{3,8}$)|( ^/([0-9]{3,4}/)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$) 支持手機號但也不完美
描述
上海:02112345678 3+8位
上海:021-12345678
上海:(021)-12345678
上海:(021)12345678
鄭州:03711234567 4+7位
杭州:057112345678 4+8位
還有帶上分機號,國家碼的情況由於情況非常複雜所以不建議前台做100%驗證,到目前為止似乎也沒有誰能寫一個包含所有的類型 如果誰有更好 的驗證電話的請留言,其實有很多情況本身就是矛盾的。
匹配的例子
不匹配的例子

驗證護照 
表達式
(P/d{7})|G/d{8})
描述驗證P+7個數字和G+8個數字
匹配的例子
不匹配的例子

驗證IP 
表達式
^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9 ]{1}|[1-9])/.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}| [1-9]{1}[0-9]{1}|[1-9]|0)/.(25[0-5]|2[0-4][0-9]|[0- 1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)/.(25[0-5]|2 [0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9] )$
描述驗證IP
匹配的例子192.168.0.1 222.234.1.4
不匹配的例子

驗證域
表達式
^[a-zA-Z0-9]+([a-zA-Z0-9/-/.]+)?/.(com|org|net|cn|com.cn|edu.cn|grv.cn |)$
描述驗證域
匹配的例子csdn.net baidu.com it.com.cn
不匹配的例子192.168.0.1

驗證信用卡
表達式
^((?:4/d{3})|(?:5[1-5]/d{2})|(?:6011)|(?:3[68]/d{2})|( ?:30[012345]/d))[ -]?(/d{4})[ -]?(/d{4})[ -]?(/d{4}|3[4,7]/ d{13})$
描述驗證VISA卡,萬事達卡,Discover卡,美國運通卡
匹配的例子
不匹配的例子

驗證ISBN 國際標準書號
表達式
^(/d[- ]*){9}[/dxX]$
描述驗證ISBN國際標準書號
匹配的例子7-111-19947-2
不匹配的例子

驗證GUID 全球唯一標識符
表達式
^[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0- 9]{12}$
描述格式8-4-4-4-12
匹配的例子2064d355-c0b9-41d8-9ef7-9d8b26524751
不匹配的例子

驗證文件路徑和擴展名
表達式
^([a-zA-Z]/:|//)//([^//]+//)*[^//:*?"<>|]+/.txt(l)?$
描述檢查路徑和文件擴展名
匹配的例子E:/mo.txt
不匹配的例子E:/ , mo.doc, E:/mo.doc ,

驗證Html顏色值
表達式
^#?([af]|[AF]|[0-9]){3}(([af]|[AF]|[0-9]){3})?$
描述檢查顏色取值
匹配的例子#FF0000
不匹配的例子


正則表達式 (regex) 實戰 II (part 3)

0



A newspaper (often just called a paper when the context is clear) is a periodical publication containing news, other informative articles (listed below), and usually advertising. A newspaper is usually printed on relatively inexpensive, low-grade paper such as newsprint. The news organizations that publish newspapers are themselves often metonymically called newspapers. Most newspapers now publish online as well as in print. The online versions are called online newspapers or news sites. 60666066

Name : Chan Tai Man
Tel: 24882488 , 2499 2499 , 139 6888 6888
Email : abc@gmail.com, def@yahoo.com
HKID: A123456(7) , A123456(A)
TWID: A168145309
Website : www.google.com
Time: 00:00:00

HKID
\w\d{6}[\(][\daA]\)