xai1981's blog

http://twitter.com/xai1981

MySQL のインストールと使い方 1

インストール

[root@kabosu ~]# yum install mysql-server
===================================================================
 Package                     Arch   Version       Repository Size 
===================================================================
Installing:
 mysql-server                x86_64 5.1.71-1.el6  base       8.6 M
Installing for dependencies:
 mysql                       x86_64 5.1.71-1.el6  base       893 k
 perl-DBD-MySQL              x86_64 4.013-3.el6   base       134 k
 perl-DBI                    x86_64 1.609-4.el6   base       705 k
Updating for dependencies:
 mysql-libs                  x86_64 5.1.71-1.el6  base       1.2 M
 openssl                     x86_64 1.0.1e-15.el6 base       1.5 M
 openssl-devel               x86_64 1.0.1e-15.el6 base       1.2 M

Transaction Summary
===================================================================
Install       4 Package(s)
Upgrade       3 Package(s)
Complete!

設定ファイルの変更

[root@kabosu /etc]# diff -u _my.cnf.default my.cnf
--- _my.cnf.default
+++ my.cnf
@@ -5,6 +5,10 @@
 # Disabling symbolic-links is recommended to prevent assorted security risks
 symbolic-links=0
 
+default-character-set=utf8
+
 [mysqld_safe]
 log-error=/var/log/mysqld.log
 pid-file=/var/run/mysqld/mysqld.pid
+
+default-character-set=utf8

起動

[root@kabosu /etc]# /etc/rc.d/init.d/mysqld start
mysqld を起動中:                                           [  OK  ]

接続

[root@kabosu ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.71 Source distribution

Copyright (c) 2000, 2013, 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> CREATE DATABASE sample;
Query OK, 1 row affected (0.02 sec)

データベース一覧の出力

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bouncehammer       |
| mysql              |
| sample             |
| test               |
+--------------------+
5 rows in set (0.00 sec)

INFORMATION_SCHEMAデータベース情報の出力

mysql> SELECT * FROM INFORMATION_SCHEMA.SCHEMATA;
+--------------+--------------------+----------------------------+------------------------+----------+
| CATALOG_NAME | SCHEMA_NAME        | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |
+--------------+--------------------+----------------------------+------------------------+----------+
| NULL         | information_schema | utf8                       | utf8_general_ci        | NULL     |
| NULL         | bouncehammer       | utf8                       | utf8_general_ci        | NULL     |
| NULL         | mysql              | utf8                       | utf8_general_ci        | NULL     |
| NULL         | sample             | utf8                       | utf8_general_ci        | NULL     |
| NULL         | test               | utf8                       | utf8_general_ci        | NULL     |
+--------------+--------------------+----------------------------+------------------------+----------+
5 rows in set (0.00 sec)

データベースの選択

mysql> use sample;
Database changed

選択中のデータベースを確認

mysql> SELECT database();
+------------+
| database() |
+------------+
| sample     |
+------------+
1 row in set (0.00 sec)
参考サイト