CentOS/RHEL 7/6/5にMySQLをインストールするメモ

1.MySQLYumの追加
For CentOS/RHEL 7
# rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

For CentOS/RHEL 6
# rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

For CentOS/RHEL 5
# rpm -Uvh http://repo.mysql.com/mysql-community-release-el5-5.noarch.rpm

For Fedora 20
# rpm -Uvh http://repo.mysql.com/mysql-community-release-fc20-5.noarch.rpm

For Fedora 19
# rpm -Uvh http://repo.mysql.com/mysql-community-release-fc19-5.noarch.rpm

For Fedora 18
# rpm -Uvh http://repo.mysql.com/mysql-community-release-fc18-5.noarch.rpm

2.MySQLのインストール
# yum install mysql-community-server

3.MySQL起動
CentOS/RHEL 6/5の場合
# service mysqld start
# service mysqld status
# service mysqld stop

CentOS/RHEL 7の場合
# systemctl status mysqld
# systemctl stop mysqld

4.MySQLの設定
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
… Success!

By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

5.mysqlに接続
CentOS/RHEL 6/5の場合
# service mysqld restart

CentOS/RHEL 7の場合
# systemctl restart mysqld
# chkconfig mysqld on
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 51
Server version: 5.5.34 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2013, 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>

「Java入門」java.util.Collections.binarySearch()のサンプル

javaコード
package com.arkgame.study;
import java.util.ArrayList;
import java.util.Collections;

public class CollectionDemo {

@SuppressWarnings(“unchecked”)
public static void main(String[] args) {
@SuppressWarnings(“rawtypes”)
ArrayList nums = new ArrayList();
nums.add(2);
nums.add(23);
nums.add(32);
nums.add(43);
nums.add(53);
nums.add(63);
System.out.println(“最大の要素: ” + Collections.max(nums));
System.out.println(“最小の要素: ” + Collections.min(nums));
System.out.println(“指定された値の置き換: ” + Collections.replaceAll(nums, 0, 1));
System.out.println(“等価な要素の数を返す: ” + Collections.frequency(nums, -5));
System.out.println(“指定定されたオブジェクトを検索:” + Collections.binarySearch(nums, 3));

}

}
結果
最大の要素: 63
最小の要素: 2
指定された値の置き換: false
等価な要素の数を返す: 0
指定定されたオブジェクトを検索:-2

「Python入門」ログファイルを出力するサンプル

# vim op_log_file.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import os,time

def opLogFun(log):
f=file(log_file,’a’)
date=time.strftime(‘%Y-%m-%d %H:%M:%S’)
record = ‘%s %s\n’ %(date,log)
f.write(record)

if __name__ == ‘__main__’:
log_file=’/tmp/log_file.log’
opLogFun(‘test data1’)
opLogFun(‘test data2’)

「Java入門」ディレクトリの全てファイルを取得する方法

javaコード
package com.arkgame.study;
import java.io.File;

public class FileALLDemo {

public static void print(File f){
if(f!=null){
if(f.isDirectory()){
File[] fileArray=f.listFiles();
if(fileArray!=null){
for (int i = 0; i < fileArray.length; i++) {
print(fileArray[i]);
}
}
}
else{
System.out.println(f);
}
}
}
public static void main(String[] args) {
String fileName=”C:\\soft”+File.separator;
File f=new File(fileName);
print(f);
}

}

「SQL入門」SELECT INTO で新規テーブルを作成する方法

構文
SELECT <table1.カラム> <table2.カラム>
INTO <新規テーブル> FROM <コピー元テーブル1> <コピー元テーブル2>

SELECT
Employee.LastName
, Orders.OrderNo
INTO Employee_OrderNew_Tbl
FROM
Employee
INNER JOIN Orders
ON Employee.Id_PNO = Orders.Id_PNO

「Android入門」root化されているかどうかを確認する方法」

Javaコード
public class RootUtil {
public static boolean isDeviceRooted() {
return chkRootMethod1() || chkRootMethod2() || chkRootMethod3();
}

private static boolean chkRootMethod1() {
String buildTags = android.os.Build.TAGS;
return buildTags != null && buildTags.contains(“test-keys”);
}

private static boolean chkRootMethod2() {
String[] paths = { “/system/app/Superuser.apk”, “/sbin/su”, “/system/bin/su”, “/system/xbin/su”, “/data/local/xbin/su”, “/data/local/bin/su”, “/system/sd/xbin/su”,
“/system/bin/failsafe/su”, “/data/local/su”, “/su/bin/su”};
for (String path : paths) {
if (new File(path).exists()) return true;
}
return false;
}

private static boolean chkRootMethod3() {
Process process = null;
try {
process = Runtime.getRuntime().exec(new String[] { “/system/xbin/which”, “su” });
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
if (in.readLine() != null) return true;
return false;
} catch (Throwable t) {
return false;
} finally {
if (process != null) process.destroy();
}
}
}

「javaScript入門」in演算子の使用サンプル

JSコード
var oneArr=new Array();
oneArr[“firstKey”]=”data11″;
oneArr[“secondKey”]=”data22″;
var oneObj={};
oneObj.firstKey=”data11″;
oneObj.secondKey=”data22″;
for ( key in oneArr ) {
document.write(key+’=>’+oneArr[key]);
}
for ( key in oneObj ) {
document.write(key+’=>’+oneObj[key]);
}

「MySQL入門」UNIQUE 制約を作成するサンプル

1.一つのカラムにUNIQUE制約を追加
CREATE TABLE Member_tbl
(
User_ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
UNIQUE (User_ID)
)

2,複数のカラムにUNIQUE制約を追加
CREATE TABLE Member_tbl
(
User_ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT uc_PersonID UNIQUE (User_ID,LastName)
)

3.UNIQUE 制約を削除
ALTER TABLE Member_tbl
DROP INDEX uc_PersonID

「php入門」file_get_contents()でjsonデータを取得するサンプル

1.item.json
{
“goods”:[
{
“type”:1,
“name”:”data1″,
“product”:[
{
“id”:88,
“name”:”data2″,
“title”:” title122″,
“titleDesc”:”gg11,gg12″,
“price”:1234.00
},
{
“id”:89,
“name”:”test78″,
“title”:”data6 title13 title14″,
“titleDesc”:”desc12,desc44″,
“price”:3211.00
}
]
},
{
“type”:2,
“name”:”data5″,
“product”:[]
}
]

}
2.phpコード
<?php
$type = $_GET[‘type’];
$proId = $_GET[‘id’];
echo $type.”item type”;
echo $proId.”item Id”;
$json_string = file_get_contents(‘json/item.json’);

//JSON文字列を配列に変換
$data = json_decode($json_string, true);

//商品
function itemForeach($d,$type,$proId)
{
foreach ($d[“goods”] as $key => $value) {
if($value[“type”] == $type){
$results = $value;
}
}
foreach ($results[“product”] as $key => $value) {
if($value[“id”] == $proId){
$result = $value;
}
}
return $result;
}
$res = itemForeach($data,$type,$proId);
print_r($res);
?>

「jQuery入門」attr()とremoveAttr()でhtmlのタグ要素の設定、削除

1.a要素に複数の属性を追加
$(‘a’).attr({
href: ‘http://www.sample.com/introduction/notice.html’,
title: ‘お知らせ’,
target: ‘_blank’
});

2.img要素に複数の属性を追加
$(function() {
$(‘img’).attr({alt: ‘出身’, title: ‘東京品川’, width: 320, height: 210});

});

3.div要素のid属性を削除
$(‘div’).removeAttr(‘id’);