| MySQLのインストール |
# apt-get install MySQL-server MySQL-Max MySQL-client MySQL-shared ← インストール パッケージリストを読みこんでいます... 完了 依存情報ツリーを作成しています... 完了 * MySQL-shared は既に最新バージョンがインストールされています。 以下のパッケージが新たにインストールされます: MySQL-Max MySQL-client MySQL-server アップグレード: 0 個, 新規インストール: 3 個, 削除: 0 個, 保留: 1 個 11.7MB のアーカイブを取得する必要があります。 展開後に 23.6MB のディスク容量が追加消費されます。 取得:1 http://updates.vinelinux.org 3.2/i386/plus MySQL-server 4.0.25-0vl0 [7395kB] 取得:2 http://updates.vinelinux.org 3.2/i386/plus MySQL-Max 4.0.25-0vl0 [1630kB] 取得:3 http://updates.vinelinux.org 3.2/i386/plus MySQL-client 4.0.25-0vl0 [2666kB] 11.7MB を 4s 秒で取得しました (2678kB/s) 変更を適用しています... 準備中... ########################################### [100%] 1:MySQL-server ########################################### [ 33%] Preparing db table Preparing host table Preparing user table Preparing func table Preparing tables_priv table Preparing columns_priv table Installing all prepared tables 060212 16:46:31 /usr/sbin/mysqld: Shutdown Complete PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h Linux password 'new-password' See the manual for more instructions. Please report any problems with the /usr/bin/mysqlbug script! The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at https://order.mysql.com 2:MySQL-Max ########################################### [ 66%] Restarting mysqld. 3:MySQL-client ########################################### [100%] 完了# chkconfig mysql on ← MySQL自動起動設定 # chkconfig --list mysql ← MySQL自動起動設定確認 mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 2〜5がonならOK |
| 設定ファイルの初期設定(MySQL4.1.15以降固有) |
※ PHP利用時の注意
PHPのmbstring.internal_encoding の部分とDBの文字コードは合わせる必要があります。
default-character-set=utf8 → mbstring.internal_encoding = UTF-8
default-character-set=ujis → mbstring.internal_encoding = EUC-JP
default-character-set=sjis → mbstring.internal_encoding = SJIS
# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf ← 設定ファイルを/etcに作成 # vi /etc/my.cnf ← 設定ファイル編集 i キー(入力モード) [mysqld] ← mysqldの項目に下記を追記する デフォルトのサーバ文字コードを指定する default-character-set=utf8 ← 追記(ujis, sjis, utf8等が指定可能) サーバーの文字コード設定をクライアントでもそのまま使うようにする skip-character-set-client-handshake ← 追記 記載したら Esc キー(コマンドモード):wqで保存 # /etc/init.d/mysql restart ← 設定後MySQLを再起動 |
| MySQLのrootパスワードの設定 |
# mysql -u root ← MySQLへrootでログイン
mysql> select user,host,password from mysql.user; ← 現在の登録ユーザーとパスワードを確認
+------+-----------+------------------------------+
| user | host | password |
+------+-----------+------------------------------+
| root | localhost | 空白(まだ設定されていない) |
| | localhost | |
| root | Linux | 空白(まだ設定されていない) |
| | Linux | |
+------+-----------+------------------------------+
4 rows in set (0.00 sec)
rootユーザーのパスワードを設定
接続元ホストがlocalhostのrootユーザにパスワードを設定
mysql> set password for root@localhost=password('rootパスワード');
接続元ホストが自ホストのrootユーザにパスワードを設定
mysql> set password for root@'Linux'=password('rootパスワード');
mysql> select user,host,password from mysql.user; ← 再度、登録ユーザーとパスワードを確認
+------+-----------+----------------------------+
| user | host | password |
+------+-----------+----------------------------+
| root | localhost | ************ (設定された)|
| | localhost | |
| root | Linux | ************ (設定された)|
| | Linux | |
+------+-----------+----------------------------+
4 rows in set (0.00 sec)
mysql> delete from mysql.user where user=''; ←userが空白の匿名ユーザーの削除
mysql> select user,host,password from mysql.user; ← 匿名ユーザーが無いか確認
+------+-----------+--------------+
| user | host | password |
+------+-----------+--------------+
| root | localhost | ************ |
| root | Linux | ************ |
+------+-----------+--------------+
2 rows in set (0.00 sec)
mysql> exit ← 一旦MySQLからログアウト
Bye
# mysql -u root ← localhostのrootユーザーからパスワード無しでログインできない事を確認
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
# mysql -u root -h Linux ← 自ホストのrootユーザーからパスワード無しでログインできない事を確認
ERROR 1045: Access denied for user: 'root@Linux' (Using password: NO)
# mysql -u root -pxxxxx(rootパスワード) ← localhostのrootユーザーからログインできる事を確認
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 327 to server version: 4.0.25-Max
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> exit ← 一旦MySQLからログアウト
Bye
# mysql -u root -h Linux -pxxxxx(rootパスワード) ← 自ホストのrootユーザーからログインできる事を確認
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 328 to server version: 4.0.25-Max
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> exit ← MySQLからログアウト
Bye
|
| MySQLユーザーの作成 |
MySQL用のユーザーを作成するにはGRANTコマンドを使用します。
GRANTコマンドの構文は下記が基本となります。
mysql> grant 権限(複数指定可) DB名.テーブル名 to ユーザー名@ホスト名
identified by 'パスワード' with grant option;
※ 権限の種類や意味については本家サイトで確認してください。
# mysql -u root -pxxxxx(rootパスワード) ← rootでログイン yosiデータベースに全アクセス権を持った新規ユーザーyosiの作成(yosiは例です) mysql> grant all privileges on yosi.* to yosi@localhost identified by 'パスワード'; mysql> select user from mysql.user where user='yosi'; ← ユーザーyosiが登録を確認 mysql> exit ← 確認したらログアウト 指定したデータベースxxxx以外に勝手にDBを作成できないユーザーxxxxの作成 (下記の様に権限を複数指定する場合はカンマ( , )で区切ります。) mysql> grant insert,delete,update,select on xxxx.* to `xxxx`@localhost identified by 'パスワード'; mysql> select user from mysql.user where user='xxxx'; ← ユーザーが登録を確認 mysql> exit ← 確認したらログアウト |
| データベース、テーブルの作成と削除 |
# mysql -u root -pxxxxx(rootパスワード) ← rootでMySQLにログイン mysql> create database yosi; ← データベースyosiの作成 Query OK, 1 row affected (0.00 sec) mysql> show databases; ← データベースの確認 +----------+ | Database | +----------+ | yosi | +----------+ 1 rows in set (0.01 sec) mysql> use yosi ← データベースyosiへ接続 Database changed mysql> create table test(num int, name varchar(50)); ← testテーブルを作製 Query OK, 0 rows affected (0.03 sec) mysql> insert into test values(1,'ヨシ'); ← testテーブルへデータ(名前)を登録 Query OK, 1 row affected (0.00 sec) mysql> select * from test; ← 登録データの確認 +------+------+ | num | name | +------+------+ | 1 | ヨシ | +------+------+ 1 row in set (0.00 sec) mysql> delete from test where num=1; ← testテーブルのnum1のデータを削除 Query OK, 1 row affected (0.00 sec) mysql> select * from test; ← 登録データが削除されているか確認 Empty set (0.00 sec) mysql> drop database yosi; ← データベースyosiの削除 Query OK, 0 rows affected (0.05 sec) mysql> show databases; ← データベースの削除を確認 Empty set (0.00 sec) mysql> exit ← ログアウト Bye |
| MySQLユーザーの削除 |
# mysql -u root -pxxxxx(rootパスワード) ← rootでログイン mysql> delete from `mysql`.`user` where user = 'ユーザー名' and host = 'localhost'; mysql> delete from `mysql`.`db` where user = 'ユーザー名' and host = 'localhost'; mysql> delete from `mysql`.`tables_priv` where user = 'ユーザー名' and host = 'localhost'; mysql> delete from `mysql`.`columns_priv` where user = 'ユーザー名' and host = 'localhost'; mysql> flush privileges; ← 設定反映 mysql> exit ← ログアウト |
Copyright c Vine Linuxで自宅サーバー. 2004 All Rights Reserved.