12
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS6.3でMySQL5.6.14をソースからインストール

Posted at

CentOS6.3でMySQL5.6.14をソースからインストール

環境

# uname -a
Linux ttakahashi 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release 
CentOS release 6.3 (Final)

前提

  • CentOS6.3
  • Apache2.4.6をインストール済み
  • PHP5.5をインストール済み

MySQLのインストール

1.MySQLソースファイルのダウンロード

# cd /usr/local/src/
# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz/from/http://cdn.mysql.com/
# tar xvfz mysql-5.6.14.tar.gz
# cd /usr/local/src/mysql-5.6.14
→ configureがない・・・cmakeが必要らしい

2.cmakeソースファイルのダウンロード&インストール

# cd /usr/local/src/
# wget http://www.cmake.org/files/v2.8/cmake-2.8.12.tar.gz
# tar xvfz cmake-2.8.12.tar.gz
#  cd cmake-2.8.12
# ./configure
# make
# make install

3.MySQL インストール

# cd /usr/local/src/mysql-5.6.14
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
Curses library not found.  Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
→ エラー発生、ncurses-develが必要

ncurses-develインストール

# cd /usr/local/src/
# wget ftp://rpmfind.net/linux/centos/6.4/os/x86_64/Packages/ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
# rpm -ivh ncurses-devel-5.7-3.20090208.el6.x86_64.rpm

再度インストール

# cd /usr/local/src/mysql-5.6.14
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
→ CMakeCache.txt削除し忘れ
# rm CMakeCache.txt 
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
# make
# make install

4.初期設定

グループ、ユーザ作成

# groupadd mysql
# useradd -g mysql -d /usr/local/mysql mysql

データディレクトリを追加

# sudo mkdir /var/lib/mysql
# mkdir /var/lib/mysql
# chown -R mysql:mysql /usr/local/mysql

初期化

# /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql -basedir=/usr/local/mysql 

所有者変更

# chown mysql:mysql -R /var/lib/mysql/*

起動スクリプト作成

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

起動

# /usr/local/mysql/bin/mysql -u root 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
→ エラー発生

設定ファイルを編集

# vi /etc/my.conf
[mysqld]
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock

MySQL再起動

# /etc/init.d/mysqld restart

再度接続

/usr/local/mysql/bin/mysql -u root
接続を確認

パスワード設定

mysql> SET PASSWORD FOR root@localhost=PASSWORD('xxxxxxxxx');

5.ブラウザからの動作確認

ドキュメントルートに下記ファイルを配置

<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>MySQL Databases</title>
</head>
<body>
<?php
$conn = new mysqli('localhost', 'root', 'xxxxxxxxx');
if (!$conn) {
    die('データベース接続エラー: ' . mysql_error());
}
$stmt = $conn->prepare("SHOW DATABASES");
$stmt->execute();

$stmt->bind_result($database);
while ($stmt->fetch()) {
     echo $database;
      echo "<br>";
}
?>
</body>
</html>
12
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?