MySQLとは世界的に広く利用されているRDBMSで、マルチスレッドをサポートし数千万のレコードを持つデータベースも高速に処理を行えます。
また、CGIやJava・PHPなどの言語よりMySQLに手軽にアクセスが可能です。
# yum -y install mysql-server |
MySQL設定ファイルの変更 # vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 出力メッセージを日本語にする(追加) 注:システムロケールを UTF-8 以外にしてある場合、文字化けする場合があります。 下記は特に追加する必要はありません。(お好みでどうぞ) language=/usr/share/mysql/japanese/ [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid |
MySQLの起動 【FC1 から Fedora15 / CentOS4 / CentOS5 / CentOS6 の場合】 # /etc/rc.d/init.d/mysqld start OS起動時にMySQLを起動する # chkconfig mysqld on 【Fedora16以降 の場合】 # systemctl start mysqld.service OS起動時にMySQLを起動する # systemctl enable mysqld.service |
MySQL monitorに接続
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
「mysql」データベースのテーブル名表示
mysql> show tables from mysql;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
MySQLアカウントのrootが自動的に作成されているがパスワードが設定されていないので設定する。
rootにパスワードを設定する(パスワードを"himitsu"とする場合)
mysql> SET PASSWORD FOR root@localhost=PASSWORD('himitsu');
Query OK, 0 rows affected (0.00 sec)
MySQL monitorの終了
mysql> exit
Bye
MySQL monitorにrootで接続する(この時、"-p"オプションを指定しパスワード入力をする)
# mysql -u root -p
上記で設定したパスワード"himitsu"を入力
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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.
「use」コマンドで「mysql」データベースに切り替える。
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
データベースが変更された
Database changed
MySQLに接続できるユーザの表示
mysql> select host,user,password from user;
+---------------------+------+-------------------------------------------+
| host | user | password |
+---------------------+------+-------------------------------------------+
| localhost | root | *E66CFAC34A241C069A88922EFA68D1428A99AE945 |
| fedora.kajuhome.com | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| fedora.kajuhome.com | | |
+---------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)
パスワード無しのユーザ(匿名ユーザ)の削除
mysql> delete from user where user="";
Query OK, 2 rows affected (0.00 sec)
MySQLに接続できるユーザの表示
mysql> select host,user,password from user;
+---------------------+------+-------------------------------------------+
| host | user | password |
+---------------------+------+-------------------------------------------+
| localhost | root | *E66CFAC34A241C069A88922EFA68D1428A99AE94 |
| fedora.kajuhome.com | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
+---------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
パスワード無しのユーザが削除されたホスト「fedora.kajuhome.com」にもパスワードを設定する
mysql> SET PASSWORD FOR root@fedora.kajuhome.com=PASSWORD('himitsu');
Query OK, 0 rows affected (0.00 sec)
MySQLに接続できるユーザの表示
mysql> select host,user,password from user;
+---------------------+------+-------------------------------------------+
| host | user | password |
+---------------------+------+-------------------------------------------+
| localhost | root | *E66CFAC34A241C069A88922EFA68D1428A99AE94 |
| fedora.kajuhome.com | root | *E66CFAC34A241C069A88922EFA68D1428A99AE94 |
| 127.0.0.1 | root | |
| ::1 | root | |
+---------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
「use」コマンドで「test」データベースに切り替える。
mysql> use test
Database changed
mysql> show tables;
Empty set (0.00 sec)
「test」データベースのテーブル名表示
mysql> show tables;
Empty set (0.00 sec)
テーブルが存在しない(「test」データベースは試験用の為不要)「test」データベースの削除
mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)
データベースの表示
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
「test」データベースが削除されたMySQL monitorの終了
mysql> exit
Bye
|
サービスを起動した時に以下のメッセージが出力された場合、新しい MySQL 権限テーブルを生成すれば解決できる場合があります。
「mysql-server」起動時のログ
Table 'mysql.host' doesn't exist |
テーブル生成 # mysql_install_db |