2015年3月1日日曜日

mysql php 日本語 文字化け 対策

●問題
mysqlのサーバとクライアントともUTF-8に設定しているのに、
PHPで返ってきたクエリ結果(日本語)の部分は文字化けとなる。
mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

●対策
(1)コネクトの後に、クエリの文字コードを設定
 //connect
 $s = mysql_connect("localhost", $db_user, $db_pswd);

 //クエリの文字コード設定
 mysql_set_charset("utf8",$s);

(2)さらに、<?phpのあとに、以下を設定するとよいそうです。
 mb_language("uni");
 mb_internal_encoding("utf-8");
 mb_http_input("auto");
 mb_http_output("utf-8");



2015年2月28日土曜日

About mysql engine MyISAM and InnoDB

mysql have 2 engine, one is called MyISAM , another one is called InnoDB.

二つのエンジンについて、構造的には、
【MyISAM】
 ls -l /var/lib/mysql/database_name/
 TABLE_NAME.MYD
 TABLE_NAME.MYI
 TABLE_NAME.frm
 db.opt
【InnoDB】
 ls -l /var/lib/mysql/database_name/
 TABLE_NAME.frm ←これのみ

エンジンを調べるには、
mysql>show table status \G;
ENGINE:MYISAM

InnoDBのテーブルのレコードデータやインデックスデータは、テーブルスペースと呼ばれるファイル内に格納される。標準ではデータベースディレクトリ内に「ibdata1」という名称で作成されるファイルとなる。
InnoDBには商用のRDBMSに匹敵するトランザクション機能を持っている。









resize photo with linux command

♯ yum -y install ImageMagick

♯which convert
/usr/bin/convert

convert -resize 160x in_file.jpg out_file.jpg

变换相片尺寸
写真サイズ変更
resize photo size

htpasswd setting memo

(1).htpasswdファイルを新規作成する場合
[root@vm-fedora user_name]# htpasswd -b -c -m /etc/httpd/conf/.htpasswd user_name xxxxxxx
Adding password for user user_name

(2)既存の.htpasswdファイルへユーザーを追加する場合
htpasswd -b -m /etc/httpd/conf/.htpasswd user passwd

(3)ユーザー登録確認
cat /etc/httpd/conf/.htpasswd

(4).htaccessファイル作成
vi /target_dir/.htaccess

SSLRequireSSL
AuthUserFile /etc/httpd/conf/.htpasswd
AuthGroupFile /dev/null
AuthName "secret page"
AuthType Basic
require user user_name

FTP 500 OOPS: cannot change directory:/home/~

現象 FTP
500 OOPS: cannot change directory:/home/~

# vi /etc/sysconfig/selinux
SELINUX=enforcing

SELINUX=disabled

変更後にOSを再起動したほうがよい。



mysql password forggot

rootのパスワードを忘れてしまった場ってことはない?
下記のように対処すると、パスワードの変更を行うことができる。

(1)サービスの停止
以下のコマンドを実行して、デーモンを停止してください。
service mysqld  stop

(2)パスワード無しでログイン出来るようにMySQLを起動
#mysqld_safe --skip-grant-tables

(3)MySQLに接続して、パスワード変更
>mysql -u root mysql
mysql>use mysql;
mysql>update user set password=PASSWORD('new_password') where user='root' and host='localhost';
mysql>FLUSH PRIVILEGES;

(4)サービス起動
service mysqld restart

ODBCなど外部環境からLinuxのmysql(サーバ)に接続する

Mysqlのユーザが作成されると、ローカルからしか接続できないようになっている。

$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 81
Server version: 5.1.69 Source distribution

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> select user,host,password from mysql.user;
+-------+-----------------------+-------------------------------------------+
| user  | host                  | password                                  |
+-------+-----------------------+-------------------------------------------+
| root  | localhost             |                                           |
| root  | localhost.localdomain |                                           |
| root  | 127.0.0.1             |                                           |
|       | localhost             |                                           |
|       | localhost.localdomain |                                           |
| wp    | localhost             | *8C2FB6D9F381D4D1442EF41C174D50EFE9B0E80D |
| boke  | localhost             | *DE76F587B6C62747A1196425D31E9034A9DAB9BB |
| kakei | localhost             | *831A129AEB82E516DEB0BA92C657375D56D02DB7 |
+-------+-----------------------+-------------------------------------------+
8 rows in set (0.00 sec)

外部から接続できるように設定する。

mysql> grant all privileges on *.* to kakei@'192.168.127.0/255.255.255.0';
Query OK, 0 rows affected (0.00 sec)

kakei:外部から接続するためのユーザ
192.168.127.0:接続元のIPアドレス
255.255.255.0:ネットマスク



国際交流を促進するグローバル音楽フェスティバルについて語ろう。

タイトル:国際交流を促進するグローバル音楽フェスティバルの魅力 最近、世界中で注目を集めているのが、国際交流を促進するグローバル音楽フェスティバルです。音楽は言葉を超えて人々をつなぎ、文化や国境を越えて心を通わせる力があります。そんな音楽の力を最大限に活用し、異なる文化や国...