转载

关于mysql 5.5和5.6编译安装

mysql 5.5和5.6需要使用cmake,跟以往的mysql编译有了一点区别(以往的是configure,make,make install三部曲)

一共需要的软件如下:

软件 版本 安装
cmake make yum install cmake
make 3.75以上 yum install make
Perl yum install perl
bison 1.75 and 2.1(1.875不能用) yum install bison-devel
gcc-c++ 4.2.1或以上 yum install gcc-c++
ncurses yum install ncurses-devel

备注:centos 6.5支持很好,基本上只要安装以下的就不会有问题,关闭selinux

参考: http://dev.mysql.com/doc/refman/5.6/en/source-installation.html

编译安装

一般编译脚本:

Shell

#!/bin/bash  cd mysql源码目录  cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql / -DMYSQL_DATADIR=/app/mysql/mysql/data / -DSYSCONFDIR=/app/mysql / -DWITH_MYISAM_STORAGE_ENGINE=1 / -DWITH_INNOBASE_STORAGE_ENGINE=1 / -DWITH_MEMORY_STORAGE_ENGINE=1 / -DWITH_READLINE=1 / -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock / -DMYSQL_TCP_PORT=3306 / -DENABLED_LOCAL_INFILE=1 / -DWITH_PARTITION_STORAGE_ENGINE=1 / -DEXTRA_CHARSETS=all / -DDEFAULT_CHARSET=utf8 / -DDEFAULT_COLLATION=utf8_general_ci  make  make install  cp ./support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql

保存为bash脚本文件然后执行即可。

备注:

1.常用的参数就是以上的,其他的

参考:

http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

2.出现提示

Shell

Googletest was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source. If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://foo.bar.com:80 Configuring done Generating done Build files have been written to: /root/soft/mysql-5.6.4-m7

googletest,一个很著名的C++单元测试框架,简称gtest,有丰富的文档可以参考。

所以暂时我们不需要,加上参数-DENABLE_DOWNLOADS=0 就不会提示的,不过即便是提示了,但因为configure done了,所以也没关系。并且cmake的配置缓存会存放在当前文件夹的CMakeCache.txt文件, 需要重新编译就只需要删掉这个文件即可

3.mysql 5.5的安装包里面没有my.cnf参考文件(在源码包的support-files目录下),5.6的包和5.1以前的包里面都有,非常怪异- -,而且不同的文件(my-small.cnf, my-medium.cnf, my-large.cnf, and my-huge.cnf)分别对应不同使用规模等级的mysql配置,以下是文件使用的优先级,从上到下排序,当第一层检查到没有文件的时候就会去搜索第二层的文件,如此类推.

文件路径 用途 备注
/etc/my.cnf 全局使用
/etc/mysql/my.cnf 全局使用
SYSCONFDIR/my.cnf Global options
$MYSQL_HOME/my.cnf 服务器配置指定位置 这个就是编译参数-DSYSCONFDIR的对应位置
defaults-extra-file 由–defaults-extra-file=path这个配置决定
~/.my.cnf 用户特别配置
~/.mylogin.cnf 登录配置

详情参考: http://dev.mysql.com/doc/refman/5.6/en/option-files.html

至此编译安装完成.

初始化数据库

因为安装完成后mysql并没有数据库,主要是没有名字为mysql的数据库,这个数据库会存放mysql账号,权限等一系列的信息,是中枢,是数据库的大脑,所以需要初始化,

进入mysql的安装目录并执行初始化脚本

Shell

cd /app/mysql/scripts  ./mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data

1.错误提示

Shell

./mysql_install_db --user=mysql  FATAL ERROR: Could not find ./bin/my_print_defaults  If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation.  If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location.

需要有basedir和datadir

2.出现warning

Shell

WARNING: The host 'testyuan' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames

需要使用主机名,如果用不了话就只能用ip,并且可能有些libc库不能100%兼容

就加个主机名的hosts就好了,但只是warning,影响级别低.

启动数据库并设置root密码

可以安装提示使用mysqld_safe 启动,然后修改密码

Shell

mysqladmin -u root password 'new-password'

也可以使用之前配置好的/etc/init.d/mysql来启动,然后修改密码

Shell

service mysql start

也可以在启动后使用mysql_secure_installation 来修改密码

这些命令大部分都在mysql的安装目录,按需使用即可.

检查

检查是否可以连接

Shell

/app/mysql/bin/mysql -uroot -p Enter password: Welcome to the MySQL monitor.  Commands end with ; or /g. Your MySQL connection id is 2 Server version: 5.6.4-m7 Source distribution  Copyright (c) 2000, 2011, 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>

trouble-shooting

1.编译php使用mysql的时候报错

Shell

/app/soft/php-5.3.28/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory make: *** [ext/phar/phar.php] 错误 127 Generating phar.phar /app/soft/php-5.3.28/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory make: *** [ext/phar/phar.phar] 错误 127

按照提示检查这个文件发现少了库libmysqlclient.so.18, 如提示所述确实找不到了

Shell

ldd /app/soft/php-5.3.28/sapi/cli/php  linux-vdso.so.1 =>  (0x00007fff0ef81000)  libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003d28a00000)  libz.so.1 => /lib64/libz.so.1 (0x0000003d25e00000)  libedit.so.0 => /usr/lib64/libedit.so.0 (0x00000037b5800000)  libncurses.so.5 => /lib64/libncurses.so.5 (0x00000037b7000000)  libmysqlclient.so.18 => not found  libgmp.so.3 => /usr/lib64/libgmp.so.3 (0x0000003d03800000)  libbz2.so.1 => /lib64/libbz2.so.1 (0x0000003d2a200000)  libpcre.so.0 => /lib64/libpcre.so.0 (0x000000376e000000)  librt.so.1 => /lib64/librt.so.1 (0x0000003d26200000)  libm.so.6 => /lib64/libm.so.6 (0x0000003d26600000)  libdl.so.2 => /lib64/libdl.so.2 (0x0000003d25200000)  libnsl.so.1 => /lib64/libnsl.so.1 (0x0000003774000000)  libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x0000003dc3e00000)  libssl.so.10 => /usr/lib64/libssl.so.10 (0x0000003d03400000)  libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x0000003d03000000)  libc.so.6 => /lib64/libc.so.6 (0x0000003d25600000)  libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003d27200000)  libfreebl3.so => /usr/lib64/libfreebl3.so (0x0000003d28600000)  libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003d2ca00000)  libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003d25a00000)  /lib64/ld-linux-x86-64.so.2 (0x0000003d24e00000)  libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x0000003d2c600000)  libkrb5.so.3 => /lib64/libkrb5.so.3 (0x0000003d2a600000)  libcom_err.so.2 => /lib64/libcom_err.so.2 (0x0000003d29200000)  libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x0000003d2ae00000)  libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x0000003d2b200000)  libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x0000003d2aa00000)

最后多方检查发现,这个库是必须存在于/lib64或者/usr/lib64的,无法通过配置文件编译改变位置,而mysql 5.5 后会将这个库生成在安装目录里面,所以做了一个软连接,将他们沟通起来

Shell

ln -s /app/mysql564/lib/* /lib64/

2.mysql 5.5 启动时候报错

Shell

MySql server startup error 'The server quit without updating PID file

google了很多发现5.5都有这个问题,5.6却没有

参考: http://stackoverflow.com/questions/4963171/mysql-server-startup-error-the-server-quit-without-updating-pid-file/25683395#25683395 发现有很多解决办法,不过对于我的问题并没有作用,最后发现mysql文档有提到这个 http://dev.mysql.com/doc/refman/5.6/en/charset-server.html ,当然我也补充到里面去了。

在my.cnf里面加入参数

Shell

skip-character-set-client-handshake  collation_server=utf8_unicode_ci  character_set_server=utf8
正文到此结束
Loading...