發現一個網址整理的挺好,請各位參考:html
http://www.chenyudong.com/archives/building-mysql-5-6-from-source.html#ipython
也能夠參考個人另外一篇文章,整合到lamp中了:http://www.cnblogs.com/chinas/p/4572281.htmlmysql
一、編輯腳本cmake_mysql_install.sh,輸入如下內容:linux
#!/bin/bash #下載並安裝make yum -y install gcc #排除錯誤:configure: error: in `/usr/local/src/make-4.1': configure: error: no acceptable C compiler found in $PATH cd /usr/local/src/ wget http://ftp.gnu.org/gnu/make/make-4.1.tar.gz tar zxvf make-4.1.tar.gz cd make-4.1 ./configure make && make install #下載並安裝bison cd /usr/local/src/ wget http://alpha.gnu.org/gnu/bison/bison-2.7.91.tar.gz tar zxvf bison-2.7.91.tar.gz cd bison-2.7.91 ./configure make && make install #安裝gcc-c++ yum -y install gcc-c++ #for ubuntu: #apt-get install g++ #下載並解壓camke cd /usr/local/src/ wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz tar zxvf cmake-3.2.2.tar.gz cd cmake-3.2.2 ./bootstrap gmake && gmake install #or #make && make install #下載安裝ncurses cd /usr/local/src/ wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz tar -zxvf ncurses-5.9.tar.gz cd ncurses-5.9 ./configure make && make install #安裝mysql #首先,建立mysql用戶、組 groupadd mysql useradd -g mysql mysql -s /usr/sbin/nologin mkdir /usr/local/mysql # 建立目錄 mkdir /usr/local/mysql/data # 數據倉庫目錄 cd /usr/local/src/ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24.tar.gz #解壓安裝 tar zxvf mysql-5.6.24.tar.gz cd mysql-5.6.24 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql #安裝路徑 make && make install cd /usr/local/mysql scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql #初始化mysql數據庫 # cp support-files/my-medium.cnf /usr/local/mysql/my.cnf #copy配置文件 cp support-files/my-default.cnf /usr/local/mysql/my.cnf chown -R mysql:mysql /usr/local/mysql #更改權限
安裝MySQL可選項:c++
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ #my.cnf路徑 -DWITH_MYISAM_STORAGE_ENGINE=1 \ #支持MyIASM引擎 -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #支持InnoDB引擎 -DWITH_MEMORY_STORAGE_ENGINE=1 \ #支持Memory引擎 -DWITH_READLINE=1 \ #快捷鍵功能(我沒用過) -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \ #鏈接數據庫socket路徑 -DMYSQL_TCP_PORT=3306 \ #端口 -DENABLED_LOCAL_INFILE=1 \ #容許從本地導入數據 -DWITH_PARTITION_STORAGE_ENGINE=1 \ #安裝支持數據庫分區 -DEXTRA_CHARSETS=all \ #安裝全部的字符集 -DDEFAULT_CHARSET=utf8 \ #默認字符 -DDEFAULT_COLLATION=utf8_general_ci
二、# nano /usr/local/mysql/my.cnf ,添加如下內容(或者換成vim工具):web
[mysqld] basedir = /usr/local/mysql datadir = /usr/local/mysql/data log-error = /usr/local/mysql/mysql_error.log pid-file = /usr/local/mysql/mysql.pid user = mysql tmpdir = /tmp
注意:對於nano,要保存所作的修改,按下Ctrl+O;退出,按下Ctrl+X。若退出前沒有保存所作的修改,它會提示你是否要保存。若是不要,請按N,反之,則按Y。而後它會讓你確認要保存的文件名,確認或修改後按Enter便可。sql
若是你沒有修改好而不當心按了保存鍵,您能夠在請求確認文件名時按Ctrl+C來取消。數據庫
三、啓動MySQL:enbootstrap
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# /etc/init.d/mysqld start
四、進入MySQL命令行;ubuntu
$ mysql bash: mysql: command not found
$ which mysql /usr/bin/which: no mysql in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lot/bin:/usr/local/python27/bin:/home/lot/bin) [lot@bogon ~]$ whereis mysql mysql: /usr/lib64/mysql /usr/local/mysql /usr/share/mysql # ln -s /usr/local/mysql/bin/mysql /usr/bin
# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
# service mysqld restart
五、好了,
[root@bogon bin]# service mysqld restart ERROR! MySQL server PID file could not be found! Starting MySQL... SUCCESS! [root@bogon bin]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.24 Source distribution Copyright (c) 2000, 2015, 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 | | test | +--------------------+ 4 rows in set (0.04 sec)
六、遇到的一些錯誤整理:
6-一、安裝 bison:
checking for GNU M4 that supports accurate traces... configure: error: no acceptable m4 could be found in $PATH. GNU M4 1.4.6 or later is required; 1.4.16 or newer is recommended. GNU M4 1.4.15 uses a buggy replacement strstr on some systems. Glibc 2.9 - 2.12 and GNU M4 1.4.11 - 1.4.15 have another strstr bug.
解決方法(參考網址:http://blog.csdn.net/ldl22847/article/details/8575140)
cd /usr/local/src wget -O m4-1.4.9.tar.gz http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz tar -zvxf m4-1.4.9.tar.gz cd m4-1.4.9 ./configure make && make install
6-二、啓動MySQL:
* MySQL server PID file could not be found!
Starting MySQL
.. * The server quit without updating PID file (/usr/local/mysql/mysql.pid).
解決方法參考網址: http://www.jb51.net/article/48625.htm
我的解決方法:刪除安裝後的MySQL目錄及下面的全部文件,從新編譯安裝。
6-三、權限不夠(參考:http://www.webfxb.com/procedure/mysql/20140125_1021.html):
[root@vn /]# /etc/init.d/mysqld start -bash: /etc/init.d/mysqld: 權限不夠 [root@vn /]# service mysqld start env: /etc/init.d/mysqld: 權限不夠 [root@vn /]# chmod a+wrx /etc/init.d/mysqld 以root執行此命令 [root@vn /]# service mysqld start Starting MySQL... [肯定]
七、其餘安裝參考網址:
使用cmake安裝mysql5.5.13:http://blog.chinaunix.net/uid-10435474-id-2957157.html
linux cmake 安裝mysql5.5.11,以及更高版本:http://www.360doc.com/content/12/0304/19/2054285_191664568.shtml
Linux下的Nano命令:http://www.cnblogs.com/haichuan3000/articles/2125943.html
CMAKE安裝MYSQL 5.6.10:http://www.2cto.com/database/201305/208302.html
LINUX下使用CMAKE安裝MYSQL(源碼編譯):http://www.cnblogs.com/AloneSword/archive/2013/03/18/2966750.html
問題處理參考網址:
解決bash: mysql: command not found 的方法:http://www.jb51.net/article/34622.htm
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock':http://blog.csdn.net/wyzxg/article/details/4720041
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2):http://www.cnblogs.com/chinas/p/4504533.html