| はじめての自宅サーバ構築 - Fedora/CentOS - | Last Update | 2010/02/03 | |
| It opened to 2004/09/19. | Visitors Pageviews Today(IP/PV) |
4,747,748 20,125,103 980/3,668 |
# yum -y install mysql-server |
MySQL設定ファイルの変更 # vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock 出力メッセージを日本語にする(追加) language=/usr/share/mysql/japanese/ [mysql.server] user=mysql basedir=/var/lib [safe_mysqld] err-log=/var/log/mysqld.log |
MySQLの起動
# /etc/rc.d/init.d/mysqld start
MySQL データベースを初期化中: Installing all prepared tables
Fill help tables
To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system
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 fedora.kajuhome.com password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests
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 http://shop.mysql.com
[ OK ]
MySQL を起動中: [ OK ]
上記のメッセージはmysql-serverインストール後にはじめて起動した時に出力されます
「MySQL のrootのパスワードが未設定の為、パスワードを設定して下さい」と言う文言です。
2回目以降の起動は下記の様に、メッセージ出力されません
# /etc/rc.d/init.d/mysqld start
MySQL を起動中: [ OK ]
MySQLの停止
# /etc/rc.d/init.d/mysqld stop
MySQL を停止中: [ OK ]
|
MySQL monitorに接続
# mysql -u root
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 3.23.58
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
インストール直後のデータベース表示
mysql> show databases;
+-----------+
| Databases |
+-----------+
| mysql |
| test |
+-----------+
データベースが「mysql」と「test」の2つが存在している。
FedoraCore5 以降は MySQL Versionが 5 の為、「information_schema」も存在しています。
「mysql」データベースのテーブル名表示
mysql> show tables from mysql;
+-----------------+
| Tables_in_mysql |
+-----------------+
| columns_priv |
| db |
| func |
| host |
| tables_priv |
| user |
+-----------------+
6 rows in set (0.00 sec)
columns_priv :フィールドについてのアクセス制限
db :各データベースについてのアクセス制限
func :システムテーブル(ユーザ定義関数)
host :ホストによる制限
tables_priv :テーブルについてのアクセス制限
user :ユーザによりアクセスを制限
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 5 to server version: 3.23.58
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
「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 | 451b483e5c7325d5 |
| fedora.kajuhome.com | root | |
| fedora.kajuhome.com | | |
| localhost | | |
+------------------------+------+------------------+
4 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 | 451b483e5c7325d5 |
| fedora.kajuhome.com | root | |
+------------------------+------+------------------+
2 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 | 451b483e5c7325d5 |
| fedora.kajuhome.com | root | 451b483e5c7325d5 |
+------------------------+------+------------------+
2 rows in set (0.00 sec)
「use」コマンドで「test」データベースに切り替える。
mysql> use test
Database changed
「test」データベースのテーブル名表示
mysql> show tables;
Empty set (0.00 sec)
テーブルが存在しない(「test」データベースは試験用の為不要)「test」データベースの削除
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)
データベースの表示
mysql> show databases;
+-----------+
| Databases |
+-----------+
| mysql |
+-----------+
「test」データベースが削除されたMySQL monitorの終了
mysql> exit
Bye
|
Table 'mysql.host' doesn't exist |
テーブル生成 # mysql_install_db |