2014年1月28日 星期二

[研究] mysql-5.6.15.tar.gz 安裝(CentOS 6.5 x64)

[研究] mysql-5.6.15.tar.gz 安裝問題研究 (CentOS 6.5 x64)

2014-01-28

首先說一句:想完全照官方說明安裝於 CentOS 6.5 x64 上安裝 mysql-5.6.15.tar.gz,會有問題。

參考
http://dev.mysql.com/doc/refman/5.6/en/installing-source-distribution.html

下面為切換 su 在 /root 目錄下安裝情況
wget 若沒安裝可用 yum -y install wget 安裝
mysql-5.6.15.tar.gz 請自行下載
http://www.mysql.com/downloads/mysql/#downloads
(下拉選單選 Source Code,到最後一個)

mv   /etc/my.cnf   /etc/my.cnf.old

yum -y install  gcc  gcc-c++  ncurses*  cmake  bison

groupadd mysql
useradd -r -g mysql mysql
tar zxvf  mysql-5.6.15.tar.gz
cd mysql-5.6.15
cmake  .
make
make install

cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server

編譯可能發生問題

照官方這篇,沒有提到需要 ncurses* 套件,但是需要
http://dev.mysql.com/doc/refman/5.6/en/source-installation.html

在 cmake 過程,如果出現類似下面錯誤,請執行 rm -fr  /usr/local/mysql-5.6.15 把整個目錄砍掉
重新解壓 mysql-5.6.15.tar.gz,重新執行 cmake
( 一般若需要的套件沒先用 yum 安裝,而在 cmake 後才安裝會發生)

[root@localhost mysql-5.6.15]# cmake .
....(略)
CMake Error at /usr/share/cmake/Modules/TestBigEndian.cmake:31 (MESSAGE):
  no suitable type found
Call Stack (most recent call first):
  configure.cmake:626 (TEST_BIG_ENDIAN)
  CMakeLists.txt:390 (INCLUDE)

-- Configuring incomplete, errors occurred!
[root@localhost mysql-5.6.15]#

起動可能發生問題

起動 mysql 可能出現下面問題,一執行馬上就結束

[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 18853
[root@localhost mysql]# 140128 16:33:11 mysqld_safe Logging to '/var/log/mysqld.log'.
140128 16:33:11 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140128 16:33:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    /usr/local/mysql/bin/mysqld_safe --user=mysql
[root@localhost mysql]#

檢查 Log 的錯誤

[root@localhost mysql]# cat /var/log/mysqld.log  | grep ERROR
2014-01-29 11:43:00 17103 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2014-01-29 11:43:02 17103 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2014-01-29 11:43:02 17103 [ERROR] Can't start server: can't create PID file: No such file or directory
[root@localhost mysql]#

照 log 要求執行  mysql_upgrade 會失敗

[root@localhost mysql]# find / -name mysql_upgrade
/root/mysql-5.6.15/client/mysql_upgrade
/usr/local/mysql/bin/mysql_upgrade

[root@localhost mysql]# /usr/local/mysql/bin/mysql_upgrade
Looking for 'mysql' as: /usr/local/mysql/bin/mysql
Looking for 'mysqlcheck' as: /usr/local/mysql/bin/mysqlcheck
FATAL ERROR: Upgrade failed
[root@localhost mysql]#

***************************************

開始研究問題

安裝過程中,其中 scripts/mysql_install_db --user=mysql 會在 /usr/local/mysql/data 目錄建立一些資料庫檔案

[root@centos1 mysql]# ls -al /var/lib/mysql
ls: cannot access /var/lib/mysql: No such file or directory

[root@centos1 mysql]# ls -al /usr/local/mysql/data
total 110612
drwxr-xr-x.  5 mysql mysql     4096 Jan 29 13:04 .
drwxr-xr-x. 13 root  mysql     4096 Jan 29 13:04 ..
-rw-rw----.  1 mysql mysql 12582912 Jan 29 13:04 ibdata1
-rw-rw----.  1 mysql mysql 50331648 Jan 29 13:04 ib_logfile0
-rw-rw----.  1 mysql mysql 50331648 Jan 29 13:04 ib_logfile1
drwx------.  2 mysql mysql     4096 Jan 29 13:04 mysql
drwx------.  2 mysql mysql     4096 Jan 29 13:04 performance_schema
drwxr-xr-x.  2 mysql mysql     4096 Jan 29 13:02 test
[root@centos1 mysql]#

系統中發現有兩個 my.cnf

[root@centos1 mysql]# ls -al /etc/my.cnf
-rw-r--r--. 1 root root 251 Nov 23 07:52 /etc/my.cnf

[root@centos1 mysql]# ls -al /usr/local/mysql/my.cnf
-rw-r--r--. 1 root root 943 Jan 29 13:04 /usr/local/mysql/my.cnf

另外找機器安裝 CentOS 6.5 x64,發現尚未用 yum 安裝 mysql 或用 mysql-5.6.15.tar.gz 安裝 MySQL, /etc/my.cnf 就已經存在,內容如下

[root@localhost ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@localhost ~]#

這個 /etc/my.cnf 會有甚麼問題呢 ? 如果 mysql-5.6.15.tar.gz  安裝後,執行 bin/mysqld_safe --user=mysql &,它會參考  /etc/my.cnf,發現 datadir=/var/lib/mysql ,但目錄不存在,它會建立目錄,建立預設資料庫

[root@localhost ~]# ls -al /usr/local/mysql/data
total 110612
drwxr-xr-x.  5 mysql mysql     4096 Jan 29 11:40 .
drwxr-xr-x. 13 root  mysql     4096 Jan 29 11:41 ..
-rw-rw----.  1 mysql mysql 12582912 Jan 29 11:40 ibdata1
-rw-rw----.  1 mysql mysql 50331648 Jan 29 11:40 ib_logfile0
-rw-rw----.  1 mysql mysql 50331648 Jan 29 11:40 ib_logfile1
drwx------.  2 mysql mysql     4096 Jan 29 11:40 mysql
drwx------.  2 mysql mysql     4096 Jan 29 11:40 performance_schema
drwxr-xr-x.  2 mysql mysql     4096 Jan 29 11:38 test

[root@localhost ~]# ls -al /var/lib/mysql
total 110604
drwxr-xr-x.  2 mysql root      4096 Jan 29 11:43 .
drwxr-xr-x. 39 root  root      4096 Jan 29 11:43 ..
-rw-rw----.  1 mysql mysql       56 Jan 29 11:43 auto.cnf
-rw-rw----.  1 mysql mysql 12582912 Jan 29 11:43 ibdata1
-rw-rw----.  1 mysql mysql 50331648 Jan 29 11:43 ib_logfile0
-rw-rw----.  1 mysql mysql 50331648 Jan 29 11:43 ib_logfile1
srwxrwxrwx.  1 mysql mysql        0 Jan 29 11:43 mysql.sock

mysql-5.6.15.tar.gz 安裝的 my.cnf 幾乎是註解,如下

[root@localhost ~]# cat /usr/local/mysql/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@localhost ~]#

所以舊 /etc/my.cnf 可以留做參考,建議把它改名留下,把  mysql-5.6.15.tar.gz 安裝時產生的 /usr/local/mysql/my.cnf 拷貝過去

[root@centos1 mysql]#  mv   /etc/my.cnf   /etc/my.cnf.old
[root@centos1 mysql]#  cp   /usr/local/mysql/my.cnf   /etc/my.cnf
[root@centos1 mysql]#  rm  -fr  /var/lib/mysql

啟動 MySQL 可用

[root@localhost mysql]#  /usr/local/mysql/bin/mysqld_safe --user=mysql &

[root@localhost mysql]#  service   mysql.server   start

檢查一下

[root@localhost mysql]# ps aux | grep mysql
root     18263  0.0  0.1 106192  1528 pts/1    S    16:25   0:00 /bin/sh bin/mysqld_safe --user=mysql
mysql    18355  3.4 44.2 1007644 448204 pts/1  Sl   16:25   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
root     18379  0.0  0.0 103244   864 pts/1    S+   16:25   0:00 grep mysql
[root@localhost mysql]#

停止 MySQL

[root@localhost mysql]#  service    mysql.server   stop

或把 Process ID 用 kill -9 砍掉
[root@localhost mysql]# kill -9  18263  18355

(完)

相關文章

[研究] mysql-5.6.15.tar.gz 安裝(CentOS 6.5 x64)
http://shaurong.blogspot.tw/2014/01/mysql-5615targz-centos-65-x64.html
http://forum.icst.org.tw/phpbb/viewtopic.php?f=21&t=80713

[研究] MySQL 5.6.15 安裝(rpm)(CentOS 6.5 x64)
http://shaurong.blogspot.com/2014/01/mysql-5615-rpmcentos-65-x64.html

[研究] MySQL Community 5.6.15 版安裝(yum) (CentOS 6.5 x64)
http://shaurong.blogspot.com/2014/01/mysql-community-5615-tgz-centos-65-x64.html

[研究] 4主機 MySQL Cluster 7.3.3 架設(CentOS 6.5 x64)
http://shaurong.blogspot.tw/2014/01/4-mysql-cluster-7.html

[研究] 4主機 MySQL Cluster 7.2.10.1 架設
http://shaurong.blogspot.tw/2013/02/4-mysql-cluster-7210-1.html

[研究] 2主機 MySQL Cluster 7.2.10-1 架設
http://shaurong.blogspot.com/2013/02/2-mysql-cluster-7210-1.html

[研究] 4主機 MySQL Cluster 7.0.9 架設
http://forum.icst.org.tw/phpbb/viewtopic.php?f=10&t=17903

[研究] 雙主機 MySQL Cluster 7.0.9架設
http://forum.icst.org.tw/phpbb/viewtopic.php?f=10&t=17904

[研究] MariaDB 5.5 安裝(yum)(CentOS 6.3 x64)
http://shaurong.blogspot.com/2013/02/mariadb-55-yum-centos-63-x64.html

[研究] CentOS 5.4 x86 上 MySQL 資料庫同步(Replication)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=17824

[研究] mariadb-5.1.42 (tar.gz)(瑪利亞資料庫, MySQL) 安裝 (CentOS 5.4)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=17988

[研究] mariadb-5.2.4-Linux-i686.tar.gz 安裝 (CentOS 5.5 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=19434

[研究] mysql-5.5.14.tar.gz 安裝(失敗)(CentOS 6.0 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=20252

[研究] mysql-5.5.8.tar.gz 安裝(CentOS 5.5 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=19214

[研究] mysql-5.5.8.tar.gz 安裝(Fedora 14 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=19215

[研究] 每天自動備份 MySQL 方法
http://forum.icst.org.tw/phpbb/viewtopic.php?t=14972

[研究] 雙主機 MySQL Cluster 7.0.9 架設
http://forum.icst.org.tw/phpbb/viewtopic.php?t=17904

沒有留言:

張貼留言