MySQLの検証をしてみたいと思ったのででRedhatLinux(RHEL5.7)に導入してみました。
導入したMySQLのバージョンは5.6.11-2です。
ほぼ備忘録です。
[root@localhost]# rpm -qa |grep MySQL [root@localhost]# [root@localhost]# [root@localhost]# rpm -ivh MySQL-server-5.6.11-2.rhel5.i386.rpm Preparing... ########################################### [100%] 1:MySQL-server ########################################### [100%] 2013-05-13 23:05:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2013-05-13 23:05:06 5499 [Note] InnoDB: The InnoDB memory heap is disabled 2013-05-13 23:05:06 5499 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation 2013-05-13 23:05:06 5499 [Note] InnoDB: Compressed tables use zlib 1.2.3 2013-05-13 23:05:06 5499 [Note] InnoDB: Using Linux native AIO 2013-05-13 23:05:06 5499 [Note] InnoDB: Not using CPU crc32 instructions 2013-05-13 23:05:06 5499 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2013-05-13 23:05:06 5499 [Note] InnoDB: Completed initialization of buffer pool 2013-05-13 23:05:06 5499 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2013-05-13 23:05:06 5499 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2013-05-13 23:05:06 5499 [Note] InnoDB: Database physically writes the file full: wait... 2013-05-13 23:05:07 5499 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2013-05-13 23:05:08 5499 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2013-05-13 23:05:09 5499 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2013-05-13 23:05:09 5499 [Warning] InnoDB: New log files created, LSN=45781 2013-05-13 23:05:09 5499 [Note] InnoDB: Doublewrite buffer not found: creating new 2013-05-13 23:05:10 5499 [Note] InnoDB: Doublewrite buffer created 2013-05-13 23:05:10 5499 [Note] InnoDB: 128 rollback segment(s) are active. 2013-05-13 23:05:10 5499 [Warning] InnoDB: Creating foreign key constraint system tables. 2013-05-13 23:05:11 5499 [Note] InnoDB: Foreign key constraint system tables created 2013-05-13 23:05:11 5499 [Note] InnoDB: Creating tablespace and datafile system tables. 2013-05-13 23:05:11 5499 [Note] InnoDB: Tablespace and datafile system tables created. 2013-05-13 23:05:11 5499 [Note] InnoDB: Waiting for purge to start 2013-05-13 23:05:11 5499 [Note] InnoDB: 5.6.11 started; log sequence number 0 A random root password has been set. You will find it in '/root/.mysql_secret'. 2013-05-13 23:05:18 5499 [Note] Binlog end 2013-05-13 23:05:18 5499 [Note] InnoDB: FTS optimize thread exiting. 2013-05-13 23:05:18 5499 [Note] InnoDB: Starting shutdown... 2013-05-13 23:05:19 5499 [Note] InnoDB: Shutdown completed; log sequence number 1625977 2013-05-13 23:05:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2013-05-13 23:05:19 5541 [Note] InnoDB: The InnoDB memory heap is disabled 2013-05-13 23:05:19 5541 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation 2013-05-13 23:05:19 5541 [Note] InnoDB: Compressed tables use zlib 1.2.3 2013-05-13 23:05:19 5541 [Note] InnoDB: Using Linux native AIO 2013-05-13 23:05:20 5541 [Note] InnoDB: Not using CPU crc32 instructions 2013-05-13 23:05:20 5541 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2013-05-13 23:05:20 5541 [Note] InnoDB: Completed initialization of buffer pool 2013-05-13 23:05:20 5541 [Note] InnoDB: Highest supported file format is Barracuda. 2013-05-13 23:05:20 5541 [Note] InnoDB: 128 rollback segment(s) are active. 2013-05-13 23:05:20 5541 [Note] InnoDB: 5.6.11 started; log sequence number 1625977 2013-05-13 23:05:20 5541 [Note] Binlog end 2013-05-13 23:05:20 5541 [Note] InnoDB: FTS optimize thread exiting. 2013-05-13 23:05:20 5541 [Note] InnoDB: Starting shutdown... 2013-05-13 23:05:22 5541 [Note] InnoDB: Shutdown completed; log sequence number 1625987 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. Also, the account for the anonymous user has been removed. In addition, you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test database. This is strongly recommended for production servers. 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 http://shop.mysql.com New default config file was created as /usr/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings [root@localhost]# [root@localhost]# [root@localhost]# [root@localhost]# rpm -qa |grep MySQL MySQL-server-5.6.11-2.rhel5 [root@localhost]# [root@localhost]# [root@localhost]# ps aux | grep mysql root 5675 0.0 0.0 4016 668 pts/0 R+ 23:06 0:00 grep mysql [root@localhost]# [root@localhost]# service mysql start Starting MySQL.. [ OK ] [root@localhost]# [root@localhost]# [root@localhost]# [root@localhost]# ps aux | grep mysql root 5787 0.5 0.1 4632 1244 pts/0 S 23:08 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid mysql 5892 8.1 8.0 425688 83172 pts/0 Sl 23:08 0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid root 5922 0.0 0.0 4016 672 pts/0 R+ 23:08 0:00 grep mysql [root@localhost]# [root@localhost]# mysql -u root -p -bash: mysql: command not found [root@localhost]# [root@localhost]#
サーバを導入してもアクセスできないようで、いろいろ探ってみたら
基本的にはmysqlクライアントというコマンドラインツールを使って端末上で操作するようなので
クライアントも導入しました。
[root@localhost]# [root@localhost]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.11-2.rhel5.i386.rpm/from/http://cdn.mysql.com/ --2013-05-13 23:15:07-- http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.11-2.rhel5.i386.rpm/from/http://cdn.mysql.com/ Resolving dev.mysql.com... 137.254.60.11 Connecting to dev.mysql.com|137.254.60.11|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.11-2.rhel5.i386.rpm [following] --2013-05-13 23:15:08-- http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.11-2.rhel5.i386.rpm Resolving cdn.mysql.com... 210.143.147.161, 210.143.147.160 Connecting to cdn.mysql.com|210.143.147.161|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 22938015 (22M) [application/x-redhat-package-manager] Saving to: `MySQL-client-5.6.11-2.rhel5.i386.rpm' 100%[======================================================>] 22,938,015 1.80M/s in 9.5s 2013-05-13 23:15:18 (2.29 MB/s) - `MySQL-client-5.6.11-2.rhel5.i386.rpm' saved [22938015/22938015] [root@localhost]# [root@localhost]# [root@localhost]# rpm -ivh MySQL-client-5.6.11-2.rhel5.i386.rpm Preparing... ########################################### [100%] 1:MySQL-client ########################################### [100%] [root@localhost]# [root@localhost]# [root@localhost]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@localhost]# [root@localhost]# [root@localhost]# [root@localhost]# ll /root/.mysql_secret -rw------- 1 root root 96 May 13 23:05 /root/.mysql_secret [root@localhost]# less /root/.mysql_secret [root@localhost]# [root@localhost]# [root@localhost]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.11 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>
ここでいったんMySQLにはアクセスできました。
ただし、Passwordを変更しないと操作できないようなのでパスワードを変更しました。
mysql> SHOW DATABASES; ERROR 1820 (HY000): You must SET PASSWORD before executing this statement mysql> mysql> SET PASSWORD FOR root@localhost=PASSWORD('jagaimo'); Query OK, 0 rows affected (0.00 sec) mysql>
パスワードを「jagaimo」に変更しました。
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> mysql> CREATE DATABASE data1 DEFAULT CHARACTER SET utf8; Query OK, 1 row affected (0.00 sec) mysql> mysql> mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | data1 | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) mysql>
data1を作成してみました。
そのあと、テーブルを作ってデータを入れるところまでやりました。
mysql> USE data1; Database changed mysql> mysql> mysql> CREATE TABLE table1 ( id int, name varchar(100) ); Query OK, 0 rows affected (0.10 sec) mysql> mysql> SHOW TABLES; +-----------------+ | Tables_in_data1 | +-----------------+ | table1 | +-----------------+ 1 row in set (0.00 sec) mysql> mysql>exit [root@localhost ~]#cd /var/lib/mysql/data1 [root@localhost ~]#vi test.csv
csvファイルを作成してます。
再度MySQLに接続してデータをいれました。
mysql> mysql> LOAD DATA INFILE "test.csv" INTO TABLE table1 FIELDS TERMINATED BY ',' ENCLOSED BY '"'; Query OK, 11 rows affected (0.03 sec) Records: 11 Deleted: 0 Skipped: 0 Warnings: 0 mysql> mysql> SELECT * FROM table1; +------+----------+ | id | name | +------+----------+ | 1 | kyo | | 2 | ii | | 3 | otenki | | 4 | one-chan | | 5 | hontoni | | 6 | kirei | | 7 | kiss | | 8 | shitai | | 9 | iijan | | 10 | chotto | | 11 | kurai | +------+----------+ 11 rows in set (0.00 sec) mysql>
いったんここまで。
コマンドラインで操作するのは面倒なので
次はphpMyAdminを導入してみようと思います。
※参考
http://blog.livedoor.jp/vine_user/archives/51650747.html
※phpMyAdminに参考になりそうなブログ
http://linuxserver.jp/%E3%82%B5%E3%83%BC%E3%83%90%E6%A7%8B%E7%AF%89/db/mysql/phpmyadmin%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB.php
以上