现在的位置: 首页 > 综合 > 正文

linux下mysql源码安装全纪录

2013年08月25日 ⁄ 综合 ⁄ 共 4778字 ⁄ 字号 评论关闭

///////////////////////////////////////////////////////////////////////////
//
//   ubuntu虚拟机 源码安装mysql 记录下全部的安装过程
//

///////////////////////////////////////////////////////////////////////////

正确的安装过程 (ubuntu)
1) 下载 ncurses-5.7.tar.gz   ,安装之
 
  并源码安装之(静态库版)
  tar xvfz ncurses-5.7.tar.gz
  ./configure --prefix=/home/nemo/ncurses
  make && make install
 
  并源码安装之(动态库版)
  ./configure --prefix=/home/nemo/ncurses  -–with-shared –-without-debug
  make && make install

  设置添加安装路径到环境变量 /home/nemo/ncurses
  echo $PATH
  export PATH=$PATH:/home/nemo/ncurses

2) 下载mysql源码,安装之
 mysql-5.1.53.tar.gz
 ./configure --prefix=/home/nemo/mysql5 --with-charset=utf8 --with-extra-charsets=all --enable-assembler --with-pthread --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-named-curses-libs=/home/nemo/ncurses/lib/libncurses.a
 make && make install

如果对安装的./configure选项不明白, 可以./configure -help 查看详细信息。

3)如果需要继续安装php 参考文后面的更多内容

安装过程中的一些问题以及曲折经历说明

  注意1:ncurses的安装辅助说明
  ncurses安装的时候, 既安装了静态版本(除了指定--prefix以外,不带任何参数的.、configure),也安装了共享库版本(--with-shared),并且将安装的目录配置进了PATH环境变量,所有这些这么做,是为了后面安装mysql的时候避免出错。 因为现在我还不确定这里罗里罗嗦的做了这么多步, 到底是哪一步帮助了后面的mysql源码安装的时候不报错。 由于我没有时间尝试为啥会这样, 就把这些步骤全写上吧。
  可能有两种方式可以避免这么罗嗦的步骤,但是没有尝试
  1) 通过 apt-get 命令安装 ncurses ,自动化的配置好一些环境
  2) 通过 --prefix=/usr 也许也可以

  注意2:mysql的安装辅助说明
  2.1) 关于--with-named-curses-libs 
  如果不指定--with-named-curses-libs 该参数, ./configure 会失败。(貌似把ncurses安装在--prefix=/usr下不用指定该参数mysql会自己寻找到,没有试过)
  如果指定了--with-named-curses-libs=/usr/lib/libncursesw.so.5,./configure不会失败,但是make的时候会失败。
  如果指定了--with-named-curses-libs=/home/nemo/ncurses/lib/libncurses.a 记得刚开始的时候./configure也会失败,貌似吧ncurese路径假如PATH后就不会失败了,make也通过。所以上面采用的是这种连接静态库的方式。

  有人说使用 --with-named-curses-libs=/usr/lib/libncursesw.so.5但是在make的时候会遇到问题
  attempted static link of dynamic object `/usr/lib/libncursesw.so.5' 和我遇到的基本一样 但是去掉--with-named-curses-libs的话configure都过不去。
  所以我上面采用了静态库的方法
    这个人的关于--with-named-curses-libs 问题比较典型!
 http://blog.sina.com.cn/s/blog_606607470100ewm5.html(linux下安装mysql的郁闷)

 这个帖子里面 关于--with-named-curses-libs 的不同用法比较多
 http://dev.mysql.com/doc/refman/5.1/zh/installing.html(官方 第2章:安装MySQL)

    这个人也遇到了--with-named-curses-libs 问题, 并最终通过 yum安装的方式解决
 并有进一步的配置mysql的动作
 http://blog.sina.com.cn/s/blog_5ce87d560100kn9u.html(CentOS下安装mysql 遇到的问题)

    基本上编译过程中遇到的各种问题在这个帖子里面都有总结, 比如经典的关于--with-named-curses-libs问题
 http://holy2010.blog.51cto.com/1086044/360412(linux下apache+php安装常见问题)

 CentOS 5 常见的configure error的解决方法仅限于CentOS 5
    configure: error: No curses/termcap library found
    网上有的说法是:
    --with-named-curses-libs=/usr/lib/libncursesw.so.5
    其实是不对的,虽然能解决configure的错误,但是make的时候会提示错误,正确的做法应该是
    yum -y install ncurses-devel
    debian: apt-get install libncurses5-dev

  2.2) 关于./configure 的更多选项的含义 参考
http://frienda.m.blog.163.com/blog/static/675936522009930101055575/?fromdm&fromSearch&isFromSearchEngine=yes(LINUX下MYSQL完全安装使用指南)
# ./configure --prefix=/web/mysql 指定安装目录
--without-debug 去除debug模式
--with-extra-charsets=gb2312 添加gb2312中文字符支持
--enable-assembler 使用一些字符函数的汇编版本
--without-isam 去掉isam表类型支持 现在很少用了 isam表是一种依赖平台的表
--without-innodb 去掉innodb表支持 innodb是一种支持事务处理的表,适合企业级应用
--with-pthread 强制使用pthread库(posix线程库)
--enable-thread-safe-client 以线程方式编译客户端
--with-client-ldflags=-all-static
--with-mysqld-ldflags=-all-static 以纯静态方式编译服务端和客户端 --with-raid 激活raid支持

--prefix=/program/mysql     安装路径
--localstatedir=/var/lib/mysql    数据库文件存放路径
--with-comment=Source   
--with-server-suffix=-Community
--with-mysqld-user=mysql
--without-debug
--with-big-tables
--with-charset=gbk  utf8
--with-extra-charsets=all
--without-innodb
--with-unix-socket-path=/home/mysql/tmp/mysql.sock

参考 一份较详细的安装指南是:
http://huang.yunsong.net/2006/install-and-configure-mysql-on-linux.html

装完mysql,继续源码安装php
1) 先configure
./configure --prefix=/home/nemo/php5 --with-apxs2=/home/nemo/apache2/bin/apxs --with-mysql=/home/nemo/mysql5 --with-mysqli=mysqlnd --with-libxml-dir=/home/peterrzhan/libxml2 --enable-xml --enable-json --enable-dom --enable-hash --enable-sockets --enable-pcntl --enable-simplexml --enable-xmlreader --enable-xmlwriter --enable-sysvshm --enable-sysvsem --enable-ctype --enable-bcmath --enable-posix --enable-calendar

(测试ok)
2)make
3)make install
   一般此时会install失败,因为缺少zlib库,提示 zlib.h no such file, 查看出错的.c文件,发现通过<zlib.h>引用了zlib.h
   先把zlib库装上,并且装在系统默认的头文件以及lib库的路径下。参考文后内容
   装完以后 继续 make install, 一般即可成功。

拷贝php.ini
编译安装的话,默认是没有php.ini的,如果没有php.ini系统会使用默认的配置。
copy源码目录下的php.ini-development 到 php的安装目录/lib/php.ini

php也装完了,在最后配置一下,让apache支持php吧
在 apache2/conf/httd.conf 中加入如下配置
1)检查是否增加 LoadModule php5_module modules/libphp5.so
     (这一步一般安装php的时候自动会忘该文件增加这一行,为了保险还是检查一下)
2)
<IfModule mod_php5.c>
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php .php3
  AddType application/x-httpd-php-source .phps
</IfModule>

重启apache2即可!

源码安装zlib库
   下载 zlib库 zlib-1.2.5
    tar xvfz zlib-1.2.5 解压
    直接./configure 不指定路径,生成Makefile。 
    make
    sudo make install
    即可把zlib的相应头文件以及库 装在 /usr/local/include /usr/local/lib 下面
    按照gcc搜索头文件的规则(参考:http://blog.csdn.net/zdl1016/archive/2010/11/20/6024268.aspx)会自动找到zlib.h文件

抱歉!评论已关闭.