CentOSにMySQL5.6をインストールする
環境
インストール
既存package削除
すでになにかmysqlのpackageがインストールされているかを確認します。
インストールされているものがあれば、削除します。
$ sudo yum list installed | grep mysql mysql-libs.x86_64 5.1.73-5.el6_6 @base $ sudo yum erase mysql-libs
wgetインストール
wgetがインストールされていない場合はインストールします。
$ sudo yum install wget
RPMでMySQLをインストール
http://downloads.mysql.com/archives/community/からRPMをダウンロード
(2015/10/30時点の最新は5.6.26)
$ wget http://downloads.mysql.com/archives/get/file/MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm $ wget http://downloads.mysql.com/archives/get/file/MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm $ wget http://downloads.mysql.com/archives/get/file/MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64.rpm $ wget http://downloads.mysql.com/archives/get/file/MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm $ wget http://downloads.mysql.com/archives/get/file/MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64.rpm $ sudo yum install MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm $ sudo yum install MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm $ sudo yum install MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64.rpm $ sudo yum install MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm $ sudo yum install MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64.rpm
※ gem 'mysql2'
をbundle installしたらエラーになってしまったので、追加でMySQL-sharedもインストールしました。
Installing mysql2 0.3.18 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /home/vagrant/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20151030-23630-senrac.rb extconf.rb checking for ruby/thread.h... yes checking for rb_thread_call_without_gvl() in ruby/thread.h... yes checking for rb_thread_blocking_region()... no checking for rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes checking for rb_intern3()... yes ----- Using mysql_config at /usr/bin/mysql_config ----- checking for mysql.h... yes checking for errmsg.h... yes checking for mysqld_error.h... yes ----- Setting libpath to /usr/lib64 ----- creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling result.c result.c: In function ‘msec_char_to_uint’: result.c:186: warning: comparison between signed and unsigned integer expressions compiling infile.c compiling mysql2_ext.c compiling client.c linking shared-object mysql2/mysql2.so /usr/bin/ld: cannot find -lmysqlclient collect2: ld returned 1 exit status make: *** [mysql2.so] Error 1 make failed, exit code 2 Gem files will remain installed in /var/share/tg_mobile/tg_mobile_contents/vendor/bundle/ruby/2.2.0/gems/mysql2-0.3.18 for inspection. Results logged to /var/share/tg_mobile/tg_mobile_contents/vendor/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0-static/mysql2-0.3.18/gem_make.out An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.18'` succeeds before bundling.
確認
$ mysql --version mysql Ver 14.14 Distrib 5.6.26, for Linux (x86_64) using EditLine wrapper
$ sudo yum list installed | grep My MySQL-client.x86_64 5.6.26-1.linux_glibc2.5 @/MySQL-client-5.6.26-1.linux_glibc2.5.x86_64 MySQL-devel.x86_64 5.6.26-1.linux_glibc2.5 @/MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64 MySQL-server.x86_64 5.6.26-1.linux_glibc2.5 @/MySQL-server-5.6.26-1.linux_glibc2.5.x86_64 MySQL-shared.x86_64 5.6.26-1.linux_glibc2.5 @/MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64 MySQL-shared-compat.x86_64 5.6.26-1.linux_glibc2.5 @/MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64
設定
$ sudo cp /usr/share/mysql/my-default.cnf /etc/my.cnf $ sudo vi /etc/my.cnf ----- [mysqld] character-set-server = utf8 datadir = /var/lib/mysql socket = /var/lib/mysql/mysql.sock user = mysql symbolic-links=0
MySQL起動
$ sudo service mysql start
パスワード設定
rootのデフォルトパスワードが自動で設定されているので、確認します。
$ sudo cat /root/.mysql_secret # The random password set for the root user at Fri Oct 30 04:42:14 2015 (local time): xxxxxxxxxxxx
パスワードを変更する
$ mysql -u root -p Enter password: (デフォルトパスワードを入力します)
mysql> SET PASSWORD FOR root@localhost=PASSWORD('pass');
いちどexitして、ログインできるか確認します。
mysql> exit; $ mysql -u root -p Enter password: (新しいパスワードを入力します)