■MySQLインストール・起動
CentOS6で標準採用されているMySQLのバージョンが古い(5.1系)のでMySQL公式サイトのリポジトリを使用し、5.6系をインストールしました。
■外部repoを追加する。
1 2 |
[root@mysql01 ~]# rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm [root@mysql01 ~]# yum repolist |
■Install実行
1 2 3 |
[root@mysql01 ~]# yum install mysql mysql-server [root@mysql01 ~]# mysql --version mysql Ver 14.14 Distrib 5.6.32, for Linux (x86_64) using EditLine wrapper |
■起動・初期パスワード設定
1 2 |
[root@mysql01 ~]# /etc/init.d/mysqld start [root@mysql01 ~]# /usr/bin/mysqladmin -u root password |
■MySQLサーバへの接続
オプションはとりあえず下記を覚えておけばOK。オプションと値の間はスペースを空けなくても良い。
オプション | 意味 |
-u | ユーザ名を指定します。デフォルトの管理者権限を持つユーザはroot |
-h | ログインする Hostname/IP を指定。ちなみにMySQLはlocalhost=127.0.0.1ではないため注意。localhostはソケットファイル(/etc/my.cnf参照)を経由して接続する。 |
-p | パスワードオプション。後続にパスワードを記載することもできるがセキュリティ上好ましくない。 |
ソケットファイル経由でログインしてみる。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@mysql01 ~]# mysql -uroot -hlocalhost -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.6.32 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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. |
※ログインできないときは以下をチェック。yumインストールでいきなりログインできないのを見たことないですが、、
▽該当ファイルがない場合
/var/lib/mysql/配下にmysql:mysql権限の
mysql.sockという名前で空ファイルを作成する
▽mysqlが起動していない場合
/etc/init.d/mysqld startを実行する。
|
■Databaseが参照できることを確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@mysql01 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.6.32 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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 | +--------------------+ 3 rows in set (0.06 sec) |