PHP5入れた時点で入っているみたい
http://wiki.tinycorelinux.net/wiki:mysql_persistence_guide#installing_mysql
tcユーザで操作する。
停止
/etc/init.d/services/mysql stop
開始
/etc/init.d/services/mysql start
なんかメッセージが出る
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "ja_JP.utf8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
tcユーザの環境変数の問題なので、.ashrcで設定する。(Perlのwarning)
echo export LANGUAGE=$LANG>>/home/tc/.ashrc
echo export LC_ALL=$LANG>>/home/tc/.ashrc
echo export PERL_BADLANG=0>>/home/tc/.ashrc
さて、mysql_install_dbコマンドで、MySQLのデータディレクトリを作成します。
→あれれコマンドそのものがない・・・・Redhat系と違う・・・パス
rootパスワードの設定
mysqladmin -u root password rootroot
mysql -u root -p
Enter password: rootroot
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.17 Source distribution
Copyright (c) 2000, 2011, 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>
パスワードなしのユーザを削除
mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host       | password                                   |
+------+-----------+-------------------------------------------+
| root | localhost | *6C362347EBEAA7DF44F6D34884615A35095E80EB |
| root | box        |                                            |
| root | 127.0.0.1 |                                            |
| root | ::1        |                                            |
|       | localhost |                                            |
|       | box        |                                            |
+------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql>
なんかいろいろいるが危険らしいので消す
mysql> delete from user where password='';
Query OK, 5 rows affected (0.00 sec)
mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host       | password                                   |
+------+-----------+-------------------------------------------+
| root | localhost | *6C362347EBEAA7DF44F6D34884615A35095E80EB |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
ユーザ作成
mysqlはoracleなのでscott/tigerだ!?
CREATE USER 'scott'@'localhost' IDENTIFIED BY 'tiger';
データベース作成・・・漢字が使えるように
CREATE DATABASE testdb default character set utf8;
scottに権限を与える
GRANT ALL PRIVILEGES ON testdb.* TO 'scott'@'localhost';
反映させる
flush privileges;
確認
mysql> exit
Bye
tc@box:/tmp$ mysql -u root -p
Enter password: rootroot
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.17 Source distribution
Copyright (c) 2000, 2011, 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> use mysql;
Reading table information for completion of table and column names mysql>
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,host,password from user;
+-------+-----------+-------------------------------------------+
| user   | host       | password                                   |
+-------+-----------+-------------------------------------------+
| root   | localhost | *6C362347EBEAA7DF44F6D34884615A35095E80EB |
| scott | localhost | *F2F68D0BB27A773C1D944270E5FAFED515A3FA40 |
+-------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)
mysql> exit
Bye
tc@box:/tmp$
永続化
/etc/init.d/services/mysql stop
sudo su
HDD上に領域を確保する。
理想はパーティションを切るべきだが考えてなかったので
mkdir -p /mnt/sda1/database/data
mkdir -p /opt/env/srv/mysql
cp -fr /usr/local/mysql/data /mnt/sda1/database
cp -f /etc/my.cnf /opt/env/srv/mysql
cd /opt/env/srv/mysql
cp -p my.cnf my.cnf.org
sed -i 's/english/japanese/g' my.cnf
mkdir /home/log/mysql
chown tc:staff /home/log/mysql
chmod 775 /home/log/mysql
起動スクリプト
cd /opt/env/srv
echo rm -fr /usr/local/mysql/data>mysql.sh
echo rm -f /etc/my.cnf>>mysql.sh
echo ln -s /mnt/sda1/database/data /usr/local/mysql/data>>mysql.sh
echo ln -s /opt/env/srv/mysql/my.cnf /etc/my.cnf>>mysql.sh
echo rm -fr /var/log/mysql>>mysql.sh
echo ln -s /home/log/mysql /var/log/mysql>>mysql.sh
echo /etc/init.d/services/mysql start>>mysql.sh
echo sh /opt/env/srv/mysql.sh>>/opt/bootlocal.sh
再起動
sudo reboot
/etc/my.cnf を編集する。
sudo vi /etc/my.cnf
[client]
default-character-set=utf8
[mysqld1]
default-character-set = utf8
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
テーブル作ってテストする(文字化けもテスト)
tc@box:/ home/log/mysql$ mysql -u scott -p testdb
Enter pa ssword: tiger
Welcome to the MySQL monitor.   Commands end with ; or \g.
Your MyS QL connection id is 1
Server v ersion: 5.5.17 Source distribution
Copyrigh t (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle i s a registered trademark of Oracle Corporation and/or its
affiliat es. Other names may be trademarks of their respective
owners.
Type 'he lp;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> s tatus
-------- ------
mysql   V er 14.14 Distrib 5.5.17, for Linux (i686) using   EditLine wrapper
Connecti on id:           1
Current database:        testdb
Current user:            scott@localhost
SSL:                      Not in use
Current pager:           less -EM
Using ou tfile:           ''
Using de limiter:         ;
Server v ersion:          5.5.17 Source distribution
Protocol version:        10
Connecti on:              Localhost via UNIX socket
Server c haracterset:     latin1
Db      c haracterset:     utf8
Client c haracterset:     utf8
Conn.   c haracterset:     utf8
UNIX soc ket:             /tmp/mysql.sock
Uptime:                  2 min 25 sec
Threads: 1   Questions: 6   Slow queries: 0   Opens: 33   Flush tables: 1   Open tables: 26   Queries per second avg: 0.041
-------- ------
mysql> c reate table testtable(
    -> i d    int2,
    -> n ame text);
Query OK , 0 rows affected (0.08 sec)
mysql> i nsert into testtable values('1','test1');
Query OK , 1 row affected (0.06 sec)
mysql> i nsert into testtable values('2','test2');
Query OK , 1 row affected (0.01 sec)
mysql> i nsert into testtable values('3','test3');
Query OK , 1 row affected (0.01 sec)
mysql> i nsert into testtable values('4',' テスト 4');
Query OK , 1 row affected (0.00 sec)
mysql> s elect * from testtable;
+------+ ------------+
| id    | name        |
+------+ ------------+
|     1 | test1       |
|     2 | test2       |
|     3 | test3       |
|     4 | テスト4     | ←OK!!!
+------+ ------------+
4 rows i n set (0.00 sec)
mysql> s how variables like 'character_set%';
+------- -------------------+----------------------------------+
| Variab le_name             | Value                             |
+------- -------------------+----------------------------------+
| charac ter_set_client      | utf8                              |
| charac ter_set_connection | utf8                              |
| charac ter_set_database    | utf8                              |
| charac ter_set_filesystem | binary                            |
| charac ter_set_results     | utf8                              |
| charac ter_set_server      | latin1                            |
| charac ter_set_system      | utf8                              |
| charac ter_sets_dir        | /usr/local/mysql/share/charsets/ |
+------- -------------------+----------------------------------+
8 rows i n set (0.00 sec)
mysql> e xit
Bye