|
1: 2009-04-20 (月) 23:26:41 iseki |
| + | *** mySQL 操作メモ(一般) [#gf2d1c57] |
| + | **** 他のホストへ接続 [#m280297d] |
| + | mysql -u netp_user -h 202.26.158.3 -p |
| | | |
| + | **** テーブル参照権限を与える [#wbad8c98] |
| + | grant references on netp_exam.* to netp_user identified by 'netp_pass'; |
| + | |
| + | **** select 権限を与える [#pe45836a] |
| + | grant select on netp_exam.* to netp_user identified by 'netp_pass'; |
| + | |
| + | - データベース一覧 |
| + | show databases; |
| + | |
| + | - テーブル一覧 |
| + | use データベース名; |
| + | show tables; |
| + | |
| + | - テーブル削除 |
| + | use データベース名; |
| + | drop table テーブル名; |
| + | |
| + | - 項目削除 |
| + | delete from テーブル名 where 条件; |
| + | 例: delete from mdl_log_display where module="quiz"; |
| + | |
| + | ** データベースのチェックとリペア [#hdefc0d1] |
| + | - データベースを止めてから,チェックを行う |
| + | # /etc/init.d/mysql stop |
| + | # /usr/local/mysql/bin/myisamchk /var/mysql/[DBNAME]/*.MYI |
| + | # /etc/init.d/mysql start |
| + | |
| + | ** データベースの移行 MySQL4 -> MySQL5 [#mac7abec] |
| + | + MySQL5 を MySQL4と被らないようにインストールする. |
| + | + MySQL5 のデータベースを作成する(初期化する). |
| + | # /usr/local/mysql5/bin/mysql_install_db --user=mysql --ldata=/var/mysql5 |
| + | # cp support-files/my-medium.cnf /var/mysql5/my.cnf |
| + | # chown mysql /var/mysql5/my.cnf |
| + | # /etc/init.d/mysql5 を作る |
| + | + MySQL4 の移行するデータベース(xoops)をダンプする. |
| + | # /usr/local/mysql/bin/mysqldump -x xoops -u root -p > xoops.dump |
| + | + MySQL4 を止めて,MySQL5 を起動する. |
| + | # /etc/init.d/mysql stop |
| + | # /etc/init.d/mysql5 start |
| + | # /usr/local/mysql5/bin/mysqladmin -u root password パスワード |
| + | + MySQL5 で受け入れ側となる個別のデータベースを作成し,権限を旧データベースと同様に設定する. |
| + | mysql> create database xoops; |
| + | mysql> grant all on xoops.* to xoops_user identified by 'xoops_pass'; |
| + | + データをリストアする. |
| + | mysql> source xoops.dump xoops.dump は mysqlが読める必要がある. |
| + | + または |
| + | # /usr/local/mysql5/bin/mysql xoops -u root -p < xoops.dump |
| + | |
| + | *** データベースの移行 [#eef0fd3c] |
| + | - 移行元のデータベースの CHARSETが latin1 で EUCで保存 |
| + | - 移行先は utf8 |
| + | % mysqldump source_db source_table --default-character-set=latin1 -x -u root -p > table_data |
| + | % nkf -w table_data > table_data.utf8 |
| + | table_data.utf8内のテーブル名,CHARSETを新しいデータベースに合わせる. |
| + | % mysql dist_db -u root -p < table_data.utf8 |
| + | |
| + | ** UTF-8 で使用する場合 [#zfc6ad44] |
| + | mysql> show variables like "char%"; |
| + | +--------------------------+-----------------------------------------------+ |
| + | | Variable_name | Value | |
| + | +--------------------------+-----------------------------------------------+ |
| + | | character_set_client | latin1 | |
| + | | character_set_connection | latin1 | |
| + | | character_set_database | latin1 | |
| + | | character_set_filesystem | binary | |
| + | | character_set_results | latin1 | |
| + | | character_set_server | latin1 | |
| + | | character_set_system | utf8 | |
| + | | character_sets_dir | /usr/local/mysql-5.0.67/share/mysql/charsets/ | |
| + | +--------------------------+-----------------------------------------------+ |
| + | この場合は latin1 を utf8にする |
| + | mysql> set character_set_client=utf8; |
| + | mysql> set character_set_connection=utf8; |
| + | mysql> set character_set_database=utf8; |
| + | mysql> set character_set_results=utf8; |
| + | mysql> set character_set_server=utf8; |
| + | 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/local/mysql-5.0.67/share/mysql/charsets/ | |
| + | +--------------------------+-----------------------------------------------+ |