2017年8月9日 星期三

How To Install MySQL on CentOS 7 Note

MYSQL

  • wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
  • md5sum mysql57-community-release-el7-11.noarch.rpm
  • sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
  • sudo yum install mysql-server
  • sudo systemctl start mysqld
  • sudo systemctl status mysqld
  • sudo grep 'temporary password' /var/log/mysqld.log
  • echo 'KddRfttC3o,p'
  • sudo mysql_secure_installation
  • <enter new password>
  • no
  • y
  • y
  • y
  • y
  • y

  • mysqladmin -u root -p version
  • mysql -u root -p
  • create user 'deltaone'@'localhost' identified by 'D3lt@0n3';
  • show databases;
  • grant all privileges on *.* to 'deltaone'@'%' identified by 'D3lt@0n3' with grant option;
  • mysql -u deltaone -p
  • D3lt@0n3
  • mysql -u delta one -p < Sola_30_Schema_MySQL.sql

  • RPM Failure
  • rpm -qp --scripts SolaDDM-3.0.0.x86_64.rpm shows
  • /usr/bin/getent group deltaone || usr/sbin/groupadd -r delta one
  • /usr/bin/getent passed deltaone || /usr/sbin/useradd -r -d /usr/local/deltaone -s /bin/false deltaone

  • mysql-workbench on CentOS7
  • sudo yum install epee-release
  • sudo yum install mysql-workbench


  • deltaone D3lt@0n3

How To Install MySQL on CentOS 7


https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7


How To Install MySQL on CentOS 7

PostedDecember 1, 2016 130.3kviews MYSQL MARIADB CENTOS

Introduction

MySQL is an open-source database management system, commonly installed as part of the popular LEMP(Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data.
CentOS 7 prefers MariaDB, a fork of MySQL managed by the original MySQL developers and designed as a replacement for MySQL. If you run yum install mysql on CentOS 7, it is MariaDB that is installed rather than MySQL. If you're wondering about MySQL vs. MariaDB, MariaDB will generally work seamlessly in place of MySQL, so unless you have a specific use-case for MySQL, see the How To Install MariaDB on Centos 7 guide.
This tutorial will explain how to install MySQL version 5.7 on a CentOS 7 server.

Prerequisites

To follow this tutorial, you will need:
  • A CentOS 7 with a non-root user with sudo privileges. You can learn more about how to set up a user with these privileges in the Initial Server Setup with CentOS 7 guide.

Step 1 — Installing MySQL

As mentioned in the introduction, the Yum command to install MySQL in fact installs MariaDB. To install MySQL, we'll need to visit the MySQL community Yum Repository which provides packages for MySQL.
In a web browser, visit:
https://dev.mysql.com/downloads/repo/yum/
Note that the prominent Download links don't lead directly to the files. Instead, they lead to a subsequent page where you're invited to log in or sign up for an account. If you don't want to create an account, you can locate the text "No thanks, just start my download", then right-click and copy the link location, or you can edit the version number in the commands below.
Locate the desired version, and update it as needed in the link below:
Screencapture highlighting current yum repo name
  • wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Once the rpm file is saved, we will verify the integrity of the download by running md5sum and comparing it with the corresponding MD5 value listed on the site:
  • md5sum mysql57-community-release-el7-9.noarch.rpm
Output
1a29601dc380ef2c7bc25e2a0e25d31e mysql57-community-release-el7-9.noarch.rpm
Compare this output with the appropriate MD5 value on the site:
Screencapture highlighting md5dsum
Now that we've verified that the file wasn't corrupted or changed, we'll install the package:
  • sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm
This adds two new MySQL yum repositories, and we can now use them to install MySQL server:
  • sudo yum install mysql-server
Press y to confirm that you want to proceed. Since we've just added the package, we'll also be prompted to accept its GPG key. Press y to download it and complete the install.

Step 2 — Starting MySQL

We'll start the daemon with the following command:
  • sudo systemctl start mysqld
systemctl doesn't display the outcome of all service management commands, so to be sure we succeeded, we'll use the following command:
  • sudo systemctl status mysqld
If MySQL has successfully started, the output should contain Active: active (running) and the final line should look something like:
  • Dec 01 19:02:20 centos-512mb-sfo2-02 systemd[1]: Started MySQL Server.
Note: MySQL is automatically enabled to start at boot when it is installed. You can change that default behavior with sudo systemctl disable mysqld
During the installation process, a temporary password is generated for the MySQL root user. Locate it in the mysqld.log with this command:
  • sudo grep 'temporary password' /var/log/mysqld.log
Output
2016-12-01T00:22:31.416107Z 1 [Note] A temporary password is generated for root@localhost: mqRfBU_3Xk>r
Make note of the password, which you will need in the next step to secure the installation and where you will be forced to change it. The default password policy requires 12 characters, with at least one uppercase letter, one lowercase letter, one number and one special character.

Step 3 — Configuring MySQL

MySQL includes a security script to change some of the less secure default options for things like remote root logins and sample users.
Use this command to run the security script.
  • sudo mysql_secure_installation
This will prompt you for the default root password. As soon as you enter it, you will be required to change it.
Output
The existing password for the user account root has expired. Please set a new password. New password:
Enter a new 12-character password that contains at least one uppercase letter, one lowercase letter, one number and one special character. Re-enter it when prompted.
You'll receive feedback on the strength of your new password, and then you'll be immediately prompted to change it again. Since you just did, you can confidently say No:
Output
Estimated strength of the password: 100 Change the password for root ? (Press y|Y for Yes, any other key for No) :
After we decline the prompt to change the password again, we'll press Y and then ENTER to all the subsequent questions in order to remove anonymous users, disallow remote root login, remove the test database and access to it, and reload the privilege tables.
Now that we've secured the installation, let's test it.

Step 4 — Testing MySQL

We can verify our installation and get information about it by connecting with the mysqladmin tool, a client that lets you run administrative commands. Use the following command to connect to MySQL as root (-u root), prompt for a password (-p), and return the version.
  • mysqladmin -u root -p version
You should see output similar to this:
Output
mysqladmin  Ver 8.42 Distrib 5.7.16, for Linux on x86_64
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.

Server version          5.7.16
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 2 min 17 sec

Threads: 1  Questions: 6  Slow queries: 0  Opens: 107  Flush tables: 1  Open tables: 100  Queries per second avg: 0.043
This indicates your installation has been successful. 

Conclusion

In this tutorial, we've installed and secured MySQL on a CentOS 7 server. To learn more about using MySQL, this guide to learning more about MySQL commands can help. You might also consider implementing some additional security measures.

2017年5月18日 星期四

Java Swing

addActionListener() means the class is listenable to some actions.
The listenable classes includes
Swing: JComboBox, Jbutton, JTextField, JMenuItem, JCheckBox, JRadioButton
SwingX: JXDatePicker,

It is common to make a class extends from a listenable Swing class and implements ActionListener for actionPerformed(ActionEvent).

Classes that implements ActionListener becomes a listener that listens to some listenable classes.
When some actions happens to listenable classes, actionPerformed(ActionEvent) will be invoked.
When actionPerformed, ActionListener reacts to the action.
It is like action and reaction pair that Listenable and ActionListener comes together always.

Some common methods of ActionEvent are:
Object EventObject.getSource()
String getActionCommand() like button name
long getWhen()

2017年5月11日 星期四

買樓保值(三)之樓奴三十年(2nd edition)

http://magician__yang.mysinablog.com/index.php?op=ViewArticle&articleId=8408955

想不到今時今日竟然仲會有人問供樓年期造短啲,還錢還多啲,慳返啲息好,定係攤長嚟還好?
作為一個成年人,問呢個問題實在有點「太不食人間煙火」,搞到魔術師都唔係好想答。因為只要稍為暸解到通脹的影響,就會知道答案。
試想你人工$10,000,今年加薪3%,得$10,300,但物價上漲5%,一個本來賣$10的麵包,而家賣$10.50,結果就係你的薪金增幅追不上通脹,名義上有增加,但實際購買力有所減少。
呢個就係「實質利率」的概念,公式為:
(1+名義利率)=(1+實質利率)x(1+通脹率)
打個約數,名義利率 = 實質利率 + 通脹率,又或者實質利率 = 名義利率 - 通脹率
以上述例子觀之,薪金升幅就是名義利率,由於名義利率比通脹率低,實際利率為負數。在實際利率為負數的環境下,持有現金就會被通脹蠶食;但係如果你用$10買麵包,持有資產,則能夠「保值」。
再進一步講,在負利率環境下,欠債同樣會被通脹蠶食,所以只要唔好好似陳婉容所倡議的欠債不還,反而搞好自己的信貸紀錄,做個有借有還上等人,借錢愈多,愈攤長來還就愈著數。
魔術師不厭其煩再講一次,「借錢愈多,愈攤長來還就愈著數」的先決條件係負利率,通脹率要高過利息。
講返買樓按揭,每期還款額都係一樣,可以Excel公式PMT=(rate,nper,pv)得出;每期還款包括本金與及利息,其中利息是「息隨本減」(即利息以當期的欠款為基礎計算),期數愈後的還款,利息所佔比例愈少。
以《買樓保值(一)之先保未來錢》的試算表再計算一次:
假設:
樓價:500萬
按揭:60%
年期:30年
息率:2.5%p.a.
通脹:4.5%p.a.
月供:$11,854
按揭保費:$0
印花稅:$150,000
雙倍印花稅:$0
特別印花稅:$0
供樓利息免稅額:無(因每人收入和家庭免稅額都不同,為簡單起見,假設為0) 
經紀佣:$50,000(假設為樓價1%)
律師費:$50,000(假設為樓價1%)
30年(360個月)後供甩層樓,名義上利息供了$1,267,306,本金(當然!)供了$3,000,000萬。不過魔術師當然會認真地以現值計算,以通脹率為現折率(discount rate),將未來的本金和按揭利息折現(即未來的$1等於現在幾多錢),則按揭利息現值為$825,693,已供本金現值為$1,513,753。可以見到,供30年本金加利息的現值竟然只係234萬,加埋首期200萬,都只係434萬,比起現兜兜用500萬「抵」咗13.2%。
[講多一點,30年後供完層樓,本金、利息、再加上所有使費(如印花稅、經紀佣、律師費等),花費為現值$459萬,30年後的未來值(Future value)為$970.8萬$1,766萬(升值253%),只要30年後能夠只呢個銀碼賣出便能夠「打和」,成功保值。合計樓價複式增長只需2.24%4.30%即可成功達標。]
Picture
好,假如「供樓年期造短啲,還錢還多啲,慳返啲息」又點呢?以同樣設定,不過年期改為供10年,月供$28,281。
10年(120個月)後供甩層樓,名義上利息供了$393,716(現值$338,985),本金(當然!)供了$3,000,000萬(現值$2,389,826)。可以見到,供10年本金加利息的現值為$472.9萬,比起現兜兜用500萬買只係「抵」咗5.4%。
Picture
總結就係,如果係講緊自住樓(即係撇除要留返購買力買多層樓投資的因素),在低息高通脹的環境下,識揀嘅按揭都要有咁長做咁長,最好就係可以做三十年樓奴,而唔係好似班有青咁講,覺得供三十年樓係做奴隸。如果有現金,真係想「提早還款」慳返啲息咁點算,咪將啲錢存入去Mortgage Link戶口囉!存款既可以收同按揭一樣的存款息率(存款額最多為銀行按揭欠款的50%),又可以保持靈活性,隨時提取都無問題,係咪盞到無朋友呢?
(2nd edition:更正試算表數式錯誤。)

2017年4月27日 星期四

住宅樓宇按揭

住宅樓宇按揭

楼价$518万,首期20%即$103.6万

13 Mar 2017 付了现金$5万
28 Mar 2017 向律师楼交了支票$46.8万,以及$15.54万印花税支票
3 Apr 2017 是3星期后的首期付款日子,首期10%已经扣数
12 May 2017 成交日前要付楼价90%即$466.2万

楼价$518万,贷款80%即$414.4万,按揭保费$89096(2.15%)

按揭保费如何计算?
以按揭30年浮息按揭,一次付清保险费的保费为2.15%,每年支付的话是首年1.11%,其后0.28%。

Citibank提供的按揭内容:

户口是Citibanking而不是Citi Priority及Citigold,并且开立雇员理财计划(Citi At Work),包括货币理财组合(Currency Manager),以及港元「月月增息」支票储蓄户口(HKD Step-Up Interest Account / HKUA)。




Python traceback

import traceback

def ToTraceLines(ex, ex_traceback=None):
    if ex_traceback is None:
        ex_traceback = ex.__traceback__
    return [ line.rstrip('\n') for line in traceback.format_exception(ex.__class__, ex, ex_traceback)]
   
try:
    x = get_number()
except Exception as ex:
    ToTraceLines(ex)

2017年4月17日 星期一

dlopen and dlsym


Prepare a SO file writtern in C:
vi libso.c
#include <stdio.h>
int bejo_lib(char *name, int i) {
    printf("I am %s, do i=%d\n", name, i);
    return 0;
}
gcc -fPIC -c libso.c
gcc -shared -o libso.so libso.o

Notice the function name is not mangled because it is not C++:
nm libso.so  | grep bejo
00000000000006c8 T bejo_lib

Prepare the C user code:
vi use.c
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
    void* so = dlopen("./libso.so",RTLD_LAZY);
    printf("so: %p\n", so);
    if (!so) {
        fprintf(stderr, "%s\n", dlerror());
        exit(1);
    }
    dlerror();
    void (*fn)();
    fn = (void(*)())dlsym(so, "bejo_lib");
    printf("fn: %p\n", fn);
    if (fn) {
        fn("BEJO", 999);
    }
    dlclose(so);
    return 0;
}
// nm libso.so  | grep bejo
// 00000000000006c8 T bejo_lib
// gcc use.c -ldl -o use && ./use

The functions are mangled in the SO file libEsunnyQuot.so written in C++:
nm libEsunnyQuot.so | grep CreateEsunnyQuotClient
0000000000007c60 T _Z22CreateEsunnyQuotClientP17IEsunnyQuotNotify
nm libEsunnyQuot.so | grep DelEsunnyQuotClient
0000000000007c30 T _Z19DelEsunnyQuotClientP17IEsunnyQuotClient

Prepare the C++ user code:
vi sun.cpp
#include "EsunnyQuot.h"
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
    void* so = dlopen("./libEsunnyQuot.so",RTLD_LAZY);
    printf("so: %p\n", so);
    if (!so) {
        fprintf(stderr, "%s\n", dlerror());
        exit(1);
    }
    dlerror();
    void (*fn)(IEsunnyQuotClient*);
    fn = (void(*)(IEsunnyQuotClient*))dlsym(so, "_Z19DelEsunnyQuotClientP17IEsunnyQuotClient");
    printf("fn: %p\n", fn);
    if (fn) {
        fn(NULL);
    }
    dlclose(so);
    return 0;
}
// nm libEsunnyQuot.so | grep CreateEsunnyQuotClient
// 0000000000007c60 T _Z22CreateEsunnyQuotClientP17IEsunnyQuotNotify
// nm libEsunnyQuot.so | grep DelEsunnyQuotClient
// 0000000000007c30 T _Z19DelEsunnyQuotClientP17IEsunnyQuotClient
// gcc sun.cpp -ldl -o sun && ./sun

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...