免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2015年5月27日 星期三

html element scrollWidth, clientWidth , scrollbar width


scrollWidth(including non-viewable part) 與 clientWidth (only viewable part) 的差異在於 "viewable" or not

//=== http://www.w3schools.com/jsref/prop_element_scrollwidth.asp
"""...
The scrollWidth property returns the entire width of an element in pixels, including padding, but not the border, scrollbar or margin.

...
The scrollWidth and scrollHeight properties return the entire height and width of an element, including the height and width that is not viewable (because of overflow).



..."""


//=== http://www.w3schools.com/jsref/prop_element_clientwidth.asp

clientWidth
"""...
The clientWidth property returns the viewable height of an element
in pixels, including padding, but not the border, scrollbar or margin.
..."""




//=== https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth
"""...
The Element.scrollWidth read–only property returns either the width in pixels of the content of an element or the width of the element itself, whichever is greater. If the element is wider than its content area (for example, if there are scroll bars for scrolling through the content), the scrollWidth is larger than the clientWidth.

This property will round the value to an integer. If you need a fractional value, use element.getBoundingClientRect().

..."""



//=== scrollbar width

http://stackoverflow.com/questions/19172936/javascript-get-window-width-minus-scrollbar-width

"""...
the scrollbar is a feature of the browser and not the web page self.
Measurement should be done dynamically.
A measurement with a scrollbar and a measurement without a scrollbar
will resolve into calculating the difference in width.

..."""

the width of the scrollbar is not standard and
varies from system to system and browser to browser





2015年5月26日 星期二

html element offsetWidth, clientWidth


//=== http://www.w3schools.com/jsref/prop_element_clientwidth.asp
"""...
The clientWidth property returns the viewable height of an element
in pixels, including padding, but not the border, scrollbar or margin.
..."""


//=== http://www.w3schools.com/jsref/prop_element_offsetwidth.asp
"""...
The offsetWidth property returns the viewable width of an element
in pixels, including padding, border and scrollbar, but not the margin.
..."""


//=== http://www.w3schools.com/css/css_boxmodel.asp

css box :
from outside toward inside
margin --> border --> padding --> content

the 'width' in css style means the 'content' width --> css width ?

"""...
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}


Total element width =
width
+ left padding + right padding
+ left border + right border
+ left margin + right margin

Total element height =
height
+ top padding + bottom padding
+ top border + bottom border
+ top margin + bottom margin

..."""



2015年5月22日 星期五

html element's innerText or textContent?


//=== https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent

"""...
Differences from innerText

Internet Explorer introduced element.innerText. The intention is similar but with the following differences:

While textContent gets the content of all elements, including script> and style> elements, the IE-specific property innerText does not.
innerText is aware of style and will not return the text of hidden elements, whereas textContent will.
As innerText is aware of CSS styling, it will trigger a reflow, whereas textContent will not.


..."""



//=== http://stackoverflow.com/questions/24427621/innertext-vs-innerhtml-vs-label-vs-text-vs-textcontent-vs-outertext
text or innerText or jQuery.text()

http://www.w3schools.com/jsref/prop_option_text.asp
The text property sets or returns the text of an "option" element.


2015年5月20日 星期三

html node or element ? document or window ?


//=== node or element ?
http://www.w3schools.com/jsref/dom_obj_all.asp
"""...
In the HTML DOM (Document Object Model), everything is a node:

The document itself is a document node
All HTML elements are element nodes
All HTML attributes are attribute nodes
Text inside HTML elements are text nodes
Comments are comment nodes

..."""



//=== parentElement or parentNode ?
http://www.w3schools.com/jsref/prop_node_parentelement.asp


parentElement returns null if the parent node is not an element node

document.documentElement.parentNode; // Returns the "document" node
document.documentElement.parentElement; // Returns null

document.body.parentNode; // Returns the element
document.body.parentElement; // Returns the element


//=== document or window ?
http://www.w3schools.com/jsref/obj_window.asp

"""...
The window object represents an open window in a browser.

If a document contain frames (iframe tags), the browser creates one window object for the HTML document, and one additional window object for each frame.
..."""


//=== document object (Document object)
http://www.w3schools.com/jsref/dom_obj_document.asp

"""...
When an HTML document is loaded into a web browser, it becomes a document object.

The document object is the root node of the HTML document and the "owner" of all other nodes:
(element nodes, text nodes, attribute nodes, and comment nodes).

..."""

2015年5月14日 星期四

git, how to show history for a certain file


http://stackoverflow.com/questions/278192/view-the-change-history-of-a-file-using-git-versioning
"""...
use
$ git log -p filename
to let git generate the patches for each log entry.

...
use
$ gitk
to browse the changes visually.

...
$ git log --follow -p -- file
In other words, if the file named bar was once named foo, then git log -p bar (without the --follow option) will only show the file's history up to the point where it was renamed -- it won't show the file's history when it was known as foo.

Using git log --follow -p bar will show the file's entire history, including any changes to the file when it was known as foo.
...


..."""

after
$ git log -p file1

then scroll down to the target date you need,
copy the commit-id,

then
$ git checkout commit-id file1

$ cp file1 file1_old.bak

# restore file1 to that on master branch
$ git checkout master file1

# extract what you need from file1_old.bak to merge into file1 on branch master ...





2015年5月8日 星期五

mysql, error 1221, grant replication slave


//===
http://stackoverflow.com/questions/13552206/grant-file-on-just-one-database

ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES

mysql> grant file on johndatabase.* to 'john'@'localhost';

--> grant file on *.* to 'john'@'localhost';


mysql> grant replication slave on db1.* to 'repl001'@'192.168.42.30'

--> grant replication slave on *.* to 'repl001'@'192.168.42.30'


Both "file" and "replication slave" are Global privileges,
which cannot be granted to a specific database.



//=== confusing and conflicting setup for replication user repl_u13
mysql> grant replication slave on *.* to repl_u13@'%' identified by 'pass1';
mysql> grant replication slave on *.* to repl_u13@'192.168.42.30' identified by 'pass2';

taking either one, not both, to avoid troubles.

mysql upgrade logs


after adding mysql apt repo ( /etc/apt/sources.list.d/mysql.list will be created )
$ sudo apt-get update
$ sudo apt-get install mysql-server

"""...
...
Once you are satisfied with the configuration then select last option 'Apply' to
save the configuration. Advanced users can always change the configurations
later, depending on their own needs.

1. Server 2. Workbench 3. Connector-Python 4. Utilities 5. Apply

Which MySQL product do you wish to configure? 1


...
If you are not sure which version to
choose for yourself, do not change the auto-selected version. Advanced users can
always change the version later, depending on their own needs.

1. mysql-5.6 2. mysql-5.7-dmr 3. none

Which server version do you wish to receive? 1


...
Once you are satisfied with the configuration then select last option 'Apply' to
save the configuration. Advanced users can always change the configurations
later, depending on their own needs.

1. Server 2. Workbench 3. Connector-Python 4. Utilities 5. Apply

Which MySQL product do you wish to configure? 5

..."""


//=== backup old conf on another terminal
cp /etc/mysql/my.cnf my.cnf.bak


"""...
Configuration file '/etc/mysql/my.cnf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** my.cnf (Y/I/N/O/D/Z) [default=N] ? Y
Installing new version of config file /etc/mysql/my.cnf ...
Setting up libapparmor1:amd64 (2.8.95~2430-0ubuntu5.1) ...
Setting up libapparmor-perl (2.8.95~2430-0ubuntu5.1) ...

..."""


//===
$ nano /etc/mysql/my.cnf
$ sudo service mysql start
No directory, logging in with HOME=/
150508 06:45:50 mysqld_safe Can't log to error log and syslog at th Remove all --log-error configuration options for --syslog to take
......
* MySQL Community Server 5.6.24 did not start. Please check logs fls.

$ cat /var/log/mysql/error.log

--> $ nano /etc/mysql/my.cnf [to correct typo errors]

$ sudo service mysql start
No directory, logging in with HOME=/
150508 06:48:53 mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect.
......
* MySQL Community Server 5.6.24 is started


-->
http://serverfault.com/questions/441195/mysqld-safe-cant-log-to-error-log-and-syslog-at-the-same-time-remove-all-log
http://shinguz.blogspot.hk/2010/01/mysql-reporting-to-syslog.html
https://bugs.launchpad.net/mylvmbackup/+bug/1091950
http://dev.mysql.com/doc/refman/5.1/en/error-log.html


??? add "--skip-syslog" to the options

http://dba.stackexchange.com/questions/10117/why-is-mysql-logging-to-syslog
"""...
From 5.1.20 on, mysqld_safe has two additional error-logging options, --syslog and --skip-syslog.

In 5.1.21 and up, the default with no logging options is --skip-syslog, which is compatible with the default behavior of writing an error log file for releases prior to 5.1.20. To explicitly specify use of an error log file, specify --log-error=file_name to mysqld_safe, and mysqld_safe will arrange for mysqld to write messages to a log file. To use syslog instead, specify the --syslog option.

In 5.1.20 only, the following conditions apply: 1) The default is to use syslog, which is not compatible with releases prior to 5.1.20. 2) Logging to syslog may fail to operate correctly in some cases; if so, use --skip-syslog or --log-error.
..."""


$ cat /etc/mysql/conf.d/my.cnf
[mysqld]
bind-address=0.0.0.0

$ cat /etc/mysql/conf.d/mysqld_safe_syslog.cnf
[mysqld_safe]
syslog


-->
[mysqld_safe]
skip-syslog




mysql, how to clear master.info


https://dev.mysql.com/doc/refman/5.0/en/reset-slave.html
"""...
RESET SLAVE makes the slave forget its replication position in the master's binary log.
This statement is meant to be used for a clean start:
It deletes the master.info and relay-log.info files,
all the relay log files, and starts a new relay log file.
To use RESET SLAVE, the slave replication threads must be stopped ...
..."""


$ sudo cat /var/lib/mysql/master.info
"""
23
mysql-bin-changelog.012909
120
mysql1.chswwb1olfin.us-west-2.rds.amazonaws.com
repl_u13
pass_u13
3306
60
0
...
0
1800.000
...
0
"""

$ mysql -uroot -p
mysql> reset slave;
mysql > exit

$ sudo cat /var/lib/mysql/master.info
[sudo] password for u13:
cat: /var/lib/mysql/master.info: No such file or directory


//===
mysql> \! nano ~/change_master_to.sql
mysql> source ~/change_master_to.sql
Query OK, 0 rows affected, 2 warnings (0.65 sec)

mysql> show warnings;

| Note | 1759 | Sending passwords in plain text without SSL/TLS is extremely insecure. |
| Note | 1760 | Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information. |

mysql> start slave password='pass_u13'


mysql> show slave staus \G;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'staus' at line 1


--> typo error
mysql> show slave status \G;
"""...
1593 Last_IO_Error: Fatal error: Invalid (empty) username when attempting to connect to the master server. Connection attempt terminated.
..."""


-->
mysql> start slave user='repl_u13' password='pass_u13'


mysql> \! sudo cat /var/lib/mysql/master.info

[Q] why is master_password different from that in "start slave ... " ???

[Q] after reset slave and source the new change_master_to.sql,
master.info still shows the wrong password?


mysql reovke examples


mysql> REVOKE INSERT ON *.* FROM 'jeff'@'localhost';

mysql> REVOKE Replication Client ON *.* FROM 'repl'@'%';

mysql> REVOKE Replication Client ON *.* FROM 'repl'@'192.168.1.1';

mysql> REVOKE Replication Slave ON *.* FROM 'repl'@'%';

mysql> REVOKE Replication Slave ON *.* FROM 'repl'@'192.168.1.1';

mysql> show grants for repl;

mysql> show grants for repl@'%';

mysql> show grants for repl@'192.168.1.1';

mysql> select user,host from mysql.user;



"GRANT Replcation Slave ON *.* TO 'repl'@'%' IDENTIFIED BY PASSWORD '***********';"
disappeared

but
"GRANT USAGE ON *.* TO 'repl'@'%' IDENTIFIED BY PASSWORD '***********';"
is still there

--> http://dba.stackexchange.com/questions/13083/cant-remove-grant-usage
"""...
When you ran the REVOKE command, you simply removed the row from mysql.db. This did not touch the row in mysql.user.

...
You can't actually revoke USAGE, without dropping the user.USAGE is a global level privilege.

..."""


-->
mysql> drop user repl@'%';



//=== https://dev.mysql.com/doc/refman/5.0/en/revoke.html
To revoke all privileges,
( drops all global, database, table, column, and routine privileges for the named user or users)

mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM u11,u12,u13;



2015年5月7日 星期四

webcrawler


//=== 2015.05.07
google search webcrawler

'WebCrawler' is a registered trademark
'web crawler' is a general term to stand for the program which 'crawls' web page automatically.
--> internet bot, web scraper, web spider, web ant, web indexer?



//===
1. https://www.webcrawler.com/
Search via Google Yahoo!
hosted by InfoSpace LLC. (Bluecora Inc. ?)

main categories: web, images, videos, news

2. http://en.wikipedia.org/wiki/WebCrawler

metasearch engine


"""...
WebCrawler is a metasearch engine that blends the top search results from Google Search and Yahoo! Search.
WebCrawler also provides users the option to search for images, audio, video, news, yellow pages and white pages.
WebCrawler is a registered trademark of InfoSpace, Inc.
It went live on April 20, 1994 and was created by Brian Pinkerton at the University of Washington.

...
WebCrawler was the first Web search engine to provide 'full text search'.
It was bought by America Online on June 1, 1995 and sold to Excite on April 1, 1997.
WebCrawler was acquired by InfoSpace in 2001 ...

InfoSpace also owns and operates the metasearch engines Dogpile and MetaCrawler.

...
WebCrawler was originally a separate search engine with its own database ...
More recently it has been repositioned as a metasearch engine, providing a composite of
... search results from most of the popular search engines




..."""




3. http://en.wikipedia.org/wiki/Web_crawler

"""...
Web search engines and some other sites use Web crawling or spidering software
to update their web content or indexes of others sites' web content.
Web crawlers can copy all the pages they visit for later processing by a search engine
which "indexes" the downloaded pages so the users can search much more efficiently.

Crawlers can validate hyperlinks and HTML code. They can also be used for web scraping ...

...
"Given that the bandwidth for conducting crawls is neither infinite nor free,
it is becoming essential to crawl the Web in not only a scalable, but efficient way, ...
A crawler must carefully choose at each step which pages to visit next.


...
Crawlers usually perform some type of URL normalization in order to avoid crawling the same resource more than once.
The term URL normalization, also called URL canonicalization,
refers to the process of modifying and standardizing a URL in a consistent manner.

There are several types of normalization that may be performed including
conversion of URLs to lowercase,
removal of "." and ".." segments, and
adding trailing slashes to the non-empty path component. ...



... general open source crawlers, such as Heritrix, must be customized to filter out other MIME types, or a middleware is used to extract these documents (pdf, word, ps...) out and import them to the focused crawl database and repository....
Identifying whether these documents are academic or not is challenging and can add a significant overhead to the crawling process, so this is performed as a
post crawling process using machine learning or regular expression algorithms. ...


Coffman et al. ... they propose that a crawler must minimize the fraction of time pages remain outdated.
They also noted that the problem of Web crawling can be modeled as a multiple-queue, single-server polling system,
on which the Web crawler is the server and the Web sites are the queues.
Page modifications are the arrival of the customers, and
switch-over times are the interval between page accesses to a single Web site.

Under this model, mean waiting time for a customer in the polling system is equivalent to the average age for the Web crawler




...
Crawling the deep web
A vast amount of web pages lie in the deep or invisible web. ... typically only accessible by submitting queries to a database,
and regular crawlers are unable to find these pages if there are no links that point to them.
Google's Sitemaps protocol ... intended to allow discovery of these deep-Web resources.

...
Pages built on AJAX are among those causing problems to web crawlers. Google has proposed a format of AJAX calls that their bot can recognize and index.


...
Visual vs programmatic crawlers
...
The latest generation of "visual scrapers" like outwithub[...] and import.io[...] remove the majority of the programming skill needed to be able to program and start a crawl to scrape web data.

...
The visual scraping/crawling methodology relies on the user "teaching" a piece of crawler technology,
which then follows patterns in semi-structured data sources.
The dominant method for teaching a visual crawler is by highlighting data in a browser and
training columns and rows.
While the technology is not new, for example it was the basis of Needlebase which has been bought by Google ...
there is continued growth and investment in this area by investors and end-users


..."""


4. http://searchengineland.com/apple-confirms-their-web-crawler-applebot-220423

Applebot

"""...
Apple said, Applebot is the web crawler for Apple. AppleBot is “used by products including Siri and Spotlight Suggestions,” ...

The user-agent ... will contain “Applebot” in it always:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5 (Applebot/0.1)

Apple says it will respect the customary robots.txt rules and robots meta tags. AppleBot currently originates in the 17.0.0.0 net block. If you do not mention AppleBot in your robots.txt directive, Apple will follow what you mention for Googlebot. So if you want to block AppleBot and GoogleBot, you can just block GoogleBot, but I’d recommend you block each individually.


...
Apple is “rapidly-expanding internal search group” to build their own version of a web search engine via Spotlight.


..."""




2015 網路報稅

tax.nat 跟 etax.nat 指向不一樣的內容!!
綜所稅申報
請連 http://www.tax.nat.gov.tw/
別連 http://www.etax.nat.gov.tw/


* 電子報繳稅服務已停用SSL V3.0傳輸加密服務,請用戶改用TLS V1.0或 V1.1傳輸加密。


報稅程式在 英文版win8.1 還是有問題
[ 自動安裝版[15,957,456 位元組]建議使用。下載完成後直接執行即可進行安裝。]
中文字變成一堆亂碼
自然人憑證IC卡 久未使用
拔插了幾次 還是不行
--> unknown smart card

換用金融卡登入網路ATM , 沒問題
所以讀卡機是正常的

HiCosClient Inspector(x64) 測試
在第三項失敗 停下來 middle version?

換用舊電腦 中文繁體 win xp
安裝報稅程式, 雖然文字正常顯示
但還是一樣讀不到自然人憑證 unknown smart card

過了約20分鐘 正打算放棄之際
燈號忽然閃爍顯示有在讀取資料
執行 HiCosClient Inspector, 測試通過

執行報稅程式 讀取自然人憑證 提示輸入PIN ,
登入下載所得資料 ok

--> 不信邪, 再回到win8.1 試試, 雖然中文字亂碼,
但這回至少 讀的到 自然人憑證, 也有提示輸入PIN,
真邪門 ...



//=== 稅額試算服務

* 線上確認稅額試算書 就不用郵寄回函
* 線上確認稅額試算, 國稅局核定符合應退稅額者,退稅日期為104年7月31日

http://www.ntbna.gov.tw/etwmain/front/ETW118W/CON/1281/4938089589790683393?tagCode=

"""...
退稅案件及不繳不退案件可利用 "網路或電語語音"(退稅案件僅限沿用上年度帳戶資料)辦理回復確認,
或將書面確認申報書送交國稅局才算完成103年度綜合所得稅結算申報。

稅額試算服務線上登錄回復

1.若使用IE 7.0以上瀏覽器,建議先將服務網址 https://rtn.tax.nat.gov.tw 加入信任的網站。
2.若使用晶片金融卡線上繳稅,建議先將繳稅服務網址 https://paytax.nat.gov.tw 加入信任的網站。
3.若下載103年度稅額試算書表電子檔案,建議先將服務網址 https://pfiles.tax.nat.gov.tw 加入信任的網站。
4.若使用憑證登入下載103年度稅額試算書表電子檔案,需先安裝系統提供的ActiveX元件。 IE7及IE8如何設定安裝ActiveX元件說明; IE9如何設定安裝ActiveX元件說明。
..."""



* 稅額試算服務線上登錄(含已繳稅填寫滿意度調查)
https://rtn.tax.nat.gov.tw/ibx/ibx_login.jsp

* 103年度稅額試算書表電子檔案下載
https://pfiles.tax.nat.gov.tw/ibxpdf/ibx_pdfDownload.jsp


* 回復確認結果查詢
http://tax.nat.gov.tw/info_IBX_search.html?id=6#


//=== 要繳證所稅???
針對大戶, 小小散戶如我 毋須煩惱 ...

https://www.ntbt.gov.tw/etwmain/front/ETW118W/CON/926/8373102627425182656?tagCode=

"""...
Q20:
自102年1月1日起,證券交易所得課稅的種類有哪些?有哪些證券的證券交易所得不課稅?

A:

(一)
課徵綜合所得稅的證券:上市、上櫃、興櫃及未上市、未上櫃且未登錄興櫃(以下簡稱未上市未上櫃)的股票(包括新股權利證書、股款繳納憑證及表明其權利的證書,以下同)。

(二)
課徵基本稅額的證券:私募證券投資信託基金的受益憑證。

(三)
公債、公司債、金融債券、可轉換公司債、共同信託基金、證券投資信託基金或期貨信託基金的受益憑證、指數股票型基金(ETF)、認購(售)權證、存託憑證及證券化商品等,均非屬所得稅法第4條之1但書規定的課稅範圍,目前仍停徵綜合所得稅。

Q21:
哪些情況下的個人證券交易所得,應主動核實辦理申報?

A:
(一)
中華民國境內居住的個人有下列情形之一者:

1.
當年度出售興櫃股票數量合計在10萬股以上。

2.
初次上市、上櫃前取得的股票,於上市、上櫃以後出售。但有下列情形之一者,不包括在內:
(1)屬101年12月31日以前初次上市、上櫃的股票。
(2)屬承銷取得各該初次上市、上櫃公司股票數量在1萬股以下。

3.
出售未上市未上櫃股票。

4.
自107年起,當年度上市、上櫃及興櫃股票出售金額合計超過10億元(排除核實課稅標的及透過信託基金出售之金額)者:
課稅方式採「設算為主、核實為輔」,由國稅局歸戶後,就股票出售超過10億元之金額部分,另行發單課徵1‰所得稅。但納稅義務人亦得於結算申報時選擇就股票出售金額全數核實課稅。

(二)
非中華民國境內居住的個人出售股票。

..."""

mysql replication from remote RDS to localhost


//=== http://dba.stackexchange.com/questions/15440/replicate-rds-mysql-to-a-non-amazon-host

[errors]

ERROR 1045 (28000): Access denied for user 'repl_user'@'%' (using password: YES)

Slave I/O: error connecting to master 'repl_user@xxxx.xxxx.us-west-2.rds.amazonaws.com:3306' - retry-time: 60 retries: 11, Error_code: 1045


Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'


//=== https://www.percona.com/blog/2014/10/08/mysql-replication-got-fatal-error-1236-causes-and-cures/
max_allowed_packet
"""...
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log:
‘log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master; ...

This is a typical error on the slave(s) server. It reflects the problem around max_allowed_packet size. max_allowed_packet refers to single SQL statement sent to the MySQL server as binary log event from master to slave.

This error usually occurs when you have a different size of max_allowed_packet on the master and slave (i.e. master max_allowed_packet size is greater then slave server).

When the MySQL master server tries to send a bigger packet than defined on the slave server, the slave server then fails to accept it and hence the error.

In order to alleviate this issue please make sure to have the same value for max_allowed_packet on both slave and master.
..."""


"""...
Got fatal error 1236 from master when reading data from binary log:
‘Could not find first log file name in binary log index file’

This error occurs when the slave server required binary log for replication no longer exists on the master database server.
In one of the scenarios for this,
your slave server is stopped for some reason for a few hours/days and
when you resume replication on the slave it fails with above error.
..."""





[tips]
//=== on master side (remote RDS)
mysql> call mysql.rds_set_configuration('binlog retention hours', 24);"
mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'repl_user'@'%' IDENTIFIED BY 'repl_passwd';

[Q] is 'on *.*' must? why not only on the target database 'on db_to_be_replicated.*' ?
[Q] 'repl_user'@'%' shd be changed to 'repl_user'@'slave_public_ip' ?
[Q] is REPLICATION CLIENT optional?



//=== on slave side(localhost)

* logon to remote RDS by repl_user to verify the granted privileges
mysql -h rds_master -u repl_user -p
mysql> show grants;


* logon to localhost
mysql -uroot -p
mysql> stop slave
mysql> change master to
MASTER_HOST = 'rds.',
MASTER_PORT = 3306,
MASTER_LOG_FILE='mysql-bin.000526',
MASTER_LOG_POS=4;
xxx MASTER_USER = 'repl_user',
xxx MASTER_PASSWORD = 'xxx';


[Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE ...


[ in mysql-5.6, for security concern
remove repl_user and repl_passwd info from change master to ;
use start slave user='...' password='...' ]
mysql> start slave user='repl_user' password='repl_passwd'



2015年5月6日 星期三

mysql apt repo


//=== http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/

Steps to add add the MySQL APT Repository

0. Go to the download page for the MySQL APT repository

1. Select and download the release package for your platform.
http://dev.mysql.com/downloads/file.php?id=457235
--> http://dev.mysql.com/get/mysql-apt-config_0.3.5-1ubuntu14.04_all.deb

2. Install mysql-apt-config_xxxx.deb

shell> sudo dpkg -i /PATH/platform-and-version-specific-package-name.deb

For version w.x.y-z of the package for Ubuntu 14.04 LTS
-->
$ sudo dpkg -i mysql-apt-config_0.3.5-1ubuntu14.04_all.deb


3. Config options: You can choose none if you do not want a particular component to be installed.
After making the choices for all components, choose Apply to finish the installation of the release package.
(You can change config later)

4. $ sudo apt-get update

5. $ sudo apt-get install mysql-server (will upgrade if mysql already installed)

*** To see the packages you have installed from the MySQL APT repository,
$ dpkg -l | grep mysql | grep ii



//=== Replacing a Native Distribution of MySQL Using the MySQL APT Repository

You can replace a native distribution of MySQL installed
with a distribution from the MySQL APT repository in a few steps:

0. Backing Up Your Database
To avoid loss of data, always back up your database before trying to replace your MySQL installation using the MySQL APT repository. See Backup and Recovery for instructions.

1. Adding the MySQL APT Repository and Selecting a Release Series
Add the MySQL APT repository to your system's repository list and select the release series you want as above

2. Replacing the Native Distribution by an APT Update
By design, the MySQL APT repository replaces your native distribution of MySQL when you perform upgrades on the MySQL packages.

To perform the upgrades, just
$ sudo apt-get update
$ sudo apt-get install mysql-server

* during upgrade, choose "K" to keep the existent config?

mysqld and mysqld_safe


//=== https://dev.mysql.com/doc/refman/5.5/en/mysqld-safe.html

"""...
mysqld_safe is the recommended way to start a mysqld server on Unix.
mysqld_safe adds some safety features such as
restarting the server when an error occurs and
logging runtime information to an error log file

...
mysqld_safe tries to start an executable named mysqld.

...
Many of the options to mysqld_safe are the same as the options to mysqld.

...
mysqld_safe reads all options from the [mysqld], [server], and [mysqld_safe] sections in option files



..."""



mysql disable MyISAM


//=== http://stackoverflow.com/questions/19637477/how-to-disable-creation-of-myisam-table-in-mysql

* MyISAM engine is used by mysql system tables

* disable MyISAM storage engine is imposible
--> disable CREATE NEW MyISAM tables.

* set the default_storage_engine server variable to innodb



//=== https://mariadb.com/kb/en/mariadb/disabling-storage-engines/
"""...
mysqld --help
For all engines that can be disabled, you will see a corresponding --skip-* command line option. If the --skip-* option does not exist for a certain engine, this engine is mandatory and can not be disabled at all.

..."""

-->
$ mysqld --verbose --help
...
2015-05-06 11:42:25 1989 [Note] Binlog end
2015-05-06 11:42:25 1989 [Note] Shutting down plugin 'MyISAM'
2015-05-06 11:42:25 1989 [Note] Shutting down plugin 'CSV'




* check information_schema.tables for engines

mysql> SELECT engine,GROUP_CONCAT(DISTINCT TABLE_SCHEMA) Table_Schema_List,COUNT(*) FROM information_schema.tables GROUP BY engine;

+--------------------+--------------------------+----------+
| engine | Table_Schema_List | COUNT(*) |
+--------------------+--------------------------+----------+
| CSV | mysql | 2 |
| InnoDB | employees,fex | 7 |
| MEMORY | information_schema | 49 |
| MyISAM | mysql,information_schema | 32 |
| PERFORMANCE_SCHEMA | performance_schema | 17 |
+--------------------+--------------------------+----------+
5 rows in set (0.17 sec)




mysql table_cache


//=== https://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_key_buffer_size
"system variable"
* table_cache

Command-Line Format --table_cache=#
System Variable Name table_cache
Variable Scope Global
Dynamic Variable Yes
Permitted Values Type integer
Default 64
Min Value 1
Max Value 524288

"""...
The number of open tables for all threads.
Increasing this value increases the number of file descriptors that mysqld requires.
You can check whether you need to increase the table cache by
checking the Opened_tables status variable.
..."""


//=== "status variable"
* Opened_tables
--> https://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html

mysql> SHOW GLOBAL STATUS;


* Open_tables : The number of tables that are open.

* Opened_tables : The number of tables that have been opened.
If Opened_tables is big, your table_cache value is probably too small.




mysql key_buffer_size


//=== https://dev.mysql.com/doc/refman/5.0/en/server-parameters.html

the two most important variables for tuning mysql server performance are
* key_buffer_size
* table_cache.

"""...
If you have at least 256MB of memory and many tables and want maximum performance with a moderate number of clients, you should use something like this:

shell> mysqld_safe --key_buffer_size=64M --table_cache=256 \
--sort_buffer_size=4M --read_buffer_size=1M &

..."""



//=== https://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html

To see the values that a server will use based on its "compiled-in defaults" and any option files that it reads
$ mysqld --verbose --help

To see the values that a server will use based on its compiled-in defaults, "ignoring the settings in any option files,"
$ mysqld --no-defaults --verbose --help




* key_buffer_size

Command-Line Format --key_buffer_size=#
System Variable Name key_buffer_size
Variable Scope Global
Dynamic Variable Yes
Permitted Values Type integer
Default 8388608
Min Value 8
Max Value 4294967295

Index blocks for MyISAM tables are buffered and are shared by all threads.
key_buffer_size is the size of the buffer used for index blocks.
The key buffer is also known as the key cache.

"""...
You can increase the value to get better index handling for all reads and multiple writes;
on a system ... using the MyISAM storage engine,
25% of the machine's total memory is an acceptable value for this variable.
..."""



--> http://dba.stackexchange.com/questions/1/what-are-the-main-differences-between-innodb-and-myisam

"""...
InnoDB has row-level locking, MyISAM can only do full table-level locking.
InnoDB has better crash recovery.
MyISAM has FULLTEXT search indexes, InnoDB did not until MySQL 5.6 (Feb 2013).
InnoDB implements transactions, foreign keys and relationship constraints, MyISAM does not
..."""

* Another major difference between MyISAM and InnoDB storage engine is how caching is done:

MyISAM --> key cache(key_buffer_size).
It only caches index pages from .MYI files.

InnoDB --> InnoDB Buffer Pool(Innodb_buffer_pool_size).
It caches data and index pages from the accessed InnoDB tables.



//=== show variables for the running mysql server
$ mysqladmin variables -uroot -p
$ mysqladmin extended-status -uroot -p

or login mysql server first
$ mysql -uroot -p

then
mysql> SHOW VARIABLES;
mysql> SHOW STATUS;