新手问题 [已解决] 服务器无法安装 mysql2+ 无法 db:migrate

chairy11 · 2014年10月30日 · 最后由 chairy11 回复于 2014年10月31日 · 13332 次阅读

新问题:

已经装了 gem mysql2,但 rake db:migrate 会出错,如下: 说找不到 libmysqlclient_r.so,请问这个东东在哪里啊?或者我怎么才能让 gem 知道地址啊?

$ bin/rake db:migrate
rake aborted!
LoadError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory - /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/mysql2/mysql2.so
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/usr/local/rvm/gems/ruby-2.1.2/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
/

解决方案(感谢 @floger@flowerwrong提供):

问题的根源主要在于旧的 mysql-libs 和 Mysql 5.6 有冲突,要装 MySQL-shared-compat,官方手册有记载

$ wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm

rpm -ih MySQL-shared-5.6.15-1.el6.x86_64.rpm
$ wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-shared-compat-5.6.15-1.el6.x86_64.rpm

rpm -ih MySQL-shared-compat-5.6.15-1.el6.x86_64.rpm

旧问题

最近在学习部署服务器。 bundle install 时出错

gem install mysql2 -v '0.3.16'

用 google 来的加后缀的方法,

gem install mysql2 -v '0.3.16' -- --with-mysql-config=/usr/bin/mysql_config

但我得到同样结果,如下:

Building native extensions with: '--with-mysql-config=/usr/bin/mysql_config'
This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting libpath to /usr/lib64
-----
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling mysql2_ext.c
compiling result.c
compiling infile.c
compiling client.c
client.c: 在函数‘rb_connect’中:
client.c:331: 警告:ISO C90 不允许混合使用声明和代码
client.c:357: 警告:在有符号和无符号整数表达式间比较
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld 返回 1
make: *** [mysql2.so] 错误 1

make failed, exit code 2

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/mysql2-0.3.16 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/gem_make.out

很多解法是要求安装 mysql,但我服务器(centos 6.4)已经装了的。查询如下:

rpm -qa|grep -i MySQL

MySQL-client-5.6.15-1.el6.x86_64
MySQL-server-5.6.15-1.el6.x86_64
MySQL-devel-5.6.15-1.el6.x86_64

现在实在没有解决思路了……求解救啊!

解决方案

因为服务器上已经有别的项目在用 MySQL,我不敢像大家建议的那样先删除后安装什么的…… 结果我领导比较彪悍,直接暴力删除,然后把 gem mysql2 装上了,再恢复 mysql,发现又不行了。 最后,听说他把 libmysqlclient.a, libmysqlclient_r.a, libmysqlservices.a 放到 /usr/lib64下,就可以了…… 反正,现在是可以了,天都亮了!

谢谢各位朋友帮忙!非常感谢!

sudo yum install libmysqlclient-devel 试下, 可能库名字不对,ubuntu 的我知道,centos 的好像是这个. yum install *mysql*搜索下。

#1 楼 @flowerwrong 我不敢乱装东西啊,这个服务器还有别人在用着数据库呢。我里面有的 MySQL-devel-5.6.15-1.el6.x86_64 与你这个有什么区别?

#3 楼 @floger 555,我之前就看过了,看不懂,因为无论我用

ldconfig -p|grep mysql

还是

ldconfig -p|grep MySQL

都不显示任何结果

@ 你可以先使用 ‘’‘shell locate libmysqlclient ’‘’ 查看是否有这个 lib 包。 你使用 ldconfig -v 跟新一下 ldconfig 缓存 如果还是什么也么有的话, 安装这个 sudo yum install mysql-devel 不会影响 mysql 使用的

#1 楼 @flowerwrong

sudo yum install libmysqlclient-devel

运行结果是:

Loaded plugins: fastestmirror, refresh-packagekit
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
Setting up Install Process
No package libmysqlclient-devel available.
Error: Nothing to do

而第二句

yum install *mysql*

运行结果达好几页,摘取头尾是:

Loaded plugins: fastestmirror, refresh-packagekit
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package apr-util-mysql.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package asterisk-mysql.x86_64 0:1.8.26.1-1.el6 will be installed
--> Processing Dependency: asterisk = 1.8.26.1-1.el6 for package: asterisk-mysql-1.8.26.1-1.el6.x86_64
---> Package bacula-director-mysql.x86_64 0:5.0.0-12.el6 will be installed

# ...中间省略无数

--> Finished Dependency Resolution
Error: zabbix20 conflicts with zabbix22-2.2.1-5.el6.x86_64
Error: zabbix20 conflicts with zabbix-1.8.21-1.el6.x86_64
Error: zabbix22 conflicts with zabbix20-2.0.13-2.el6.x86_64
Error: zabbix22 conflicts with zabbix-1.8.21-1.el6.x86_64
Error: mysql-server conflicts with MySQL-server-5.6.15-1.el6.x86_64
Error: mysql-devel conflicts with MySQL-devel-5.6.15-1.el6.x86_64
 You could try using --skip-broken to work around the problem
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of mysql-libs

#5 楼 @floger 我确定里面是有 MySQL-devel-5.6.15-1.el6.x86_64 的,所以装

sudo yum install mysql-devel

会显示冲突。

另外,

locate libmysqlclient
-bash: locate: command not found

从上一个回复来看,我应该是少了

** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of mysql-libs

但我还是没有明白,MySQL-devel 和 libmysqlclient-devel 有什么区别?

MySQL-devel centos 的包名,libmysqlclient-devel 是 ubuntu 系列包名 http://unix.stackexchange.com/questions/114004/how-can-i-find-which-version-of-libmysqlclient-is-installed-in-centos 你在安装这个看看呢

sudo yum install mysql-libs

#8 楼 @floger 那其实我现在服务器有的 MySQL-devel 实际就是 ibmysqlclient-devel,两者是同一个东西罗!

头疼,我已经没法思考了…… 帮我看看我刚才的几个操作的结果……

$ yum info MySQL-devel
Loaded plugins: fastestmirror, refresh-packagekit
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
Installed Packages
Name        : MySQL-devel
Arch        : x86_64
Version     : 5.6.15
Release     : 1.el6
Size        : 19 M
Repo        : installed
Summary     : MySQL - Development header files and libraries
URL         : http://www.mysql.com/
License     : Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Under GPL license as shown in the Description field.
Description : This package contains the development header files and libraries necessary
            : to develop MySQL client applications.
            : 
            : For a description of MySQL see the base MySQL RPM or http://www.mysql.com/

Available Packages
Name        : mysql-devel
Arch        : i686
Version     : 5.1.73
Release     : 3.el6_5
Size        : 129 k
Repo        : updates
Summary     : Files for development of MySQL applications
URL         : http://www.mysql.com
License     : GPLv2 with exceptions
Description : MySQL is a multi-user, multi-threaded SQL database server. This
            : package contains the libraries and header files that are needed for
            : developing MySQL client applications.

Name        : mysql-devel
Arch        : x86_64
Version     : 5.1.73
Release     : 3.el6_5
Size        : 129 k
Repo        : updates
Summary     : Files for development of MySQL applications
URL         : http://www.mysql.com
License     : GPLv2 with exceptions
Description : MySQL is a multi-user, multi-threaded SQL database server. This
            : package contains the libraries and header files that are needed for
            : developing MySQL client applications.

$ ls /usr/lib64/mysql/libmysqlclient*
/usr/lib64/mysql/libmysqlclient.a  /usr/lib64/mysql/libmysqlclient_r.a
$ sudo yum install mysql-libs
Loaded plugins: fastestmirror, refresh-packagekit
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.73-3.el6_5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
 Package                               Arch                              Version                                     Repository                          Size
==============================================================================================================================================================
Installing:
 mysql-libs                            x86_64                            5.1.73-3.el6_5                              updates                            1.2 M

Transaction Summary
==============================================================================================================================================================
Install       1 Package(s)

Total size: 1.2 M
Installed size: 4.0 M
Is this ok [y/N]: Y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test


Transaction Check Error:
  file /usr/share/mysql/charsets/Index.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/armscii8.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/ascii.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/cp1250.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/cp1256.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/cp1257.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/cp850.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/cp852.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/cp866.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/dec8.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/geostd8.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/greek.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/hebrew.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/hp8.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/koi8r.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/koi8u.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/latin1.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/latin2.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/latin5.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/latin7.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/macce.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/macroman.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/charsets/swe7.xml from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/czech/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/danish/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/dutch/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/english/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/estonian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/french/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/german/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/greek/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/italian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/japanese/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/korean/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/polish/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/romanian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/russian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/serbian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/slovak/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/spanish/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/swedish/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64
  file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-libs-5.1.73-3.el6_5.x86_64 conflicts with file from package MySQL-server-5.6.15-1.el6.x86_64

Error Summary
-------------

#8 楼 @floger 我感觉这个输出结果是有用的,但不知道怎么用?

yum whatprovides "*libmysqlclient*"
Loaded plugins: fastestmirror, refresh-packagekit
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn

# 省略很多……

MySQL-devel-5.6.15-1.el6.x86_64 : MySQL - Development header files and libraries
Repo        : installed
Matched from:
Filename    : /usr/lib64/mysql/libmysqlclient_r.a
Filename    : /usr/lib64/mysql/libmysqlclient.a

因为我就是 MySQL-devel-5.6.15-1.el6.x86_64 这个……

sudo yum install mysql-devel

#11 楼 @huacnlee 555,不能啊,因为服务器上已经装了一个 MySQL-devel-5.6.15-1.el6.x86_64,会报错说冲突的啊!

$ sudo yum install mysql-devel
Loaded plugins: fastestmirror, refresh-packagekit
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-devel.x86_64 0:5.1.73-3.el6_5 will be installed
--> Processing Dependency: mysql = 5.1.73-3.el6_5 for package: mysql-devel-5.1.73-3.el6_5.x86_64
--> Processing Dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-devel-5.1.73-3.el6_5.x86_64
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: mysql-devel-5.1.73-3.el6_5.x86_64
--> Running transaction check
---> Package mysql.x86_64 0:5.1.73-3.el6_5 will be installed
---> Package mysql-libs.x86_64 0:5.1.73-3.el6_5 will be installed
--> Processing Conflict: mysql-devel-5.1.73-3.el6_5.x86_64 conflicts MySQL-devel
--> Finished Dependency Resolution
Error: mysql-devel conflicts with MySQL-devel-5.6.15-1.el6.x86_64
 You could try using --skip-broken to work around the problem
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-2.2.el6_1.x86_64 has missing requires of mysql-libs

#11 楼 @huacnlee #8 楼 @floger 我觉得是不是应该找个什么方法,让那个 gem mysql2 知道那个/usr/lib64/mysql/libmysqlclient_r.a 之类的位置……

MySQL-devel-5.6.15-1.el6.x86_64 : MySQL - Development header files and libraries
Repo        : installed
Matched from:
Filename    : /usr/lib64/mysql/libmysqlclient_r.a
Filename    : /usr/lib64/mysql/libmysqlclient.a

因为之前报错好像说

linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient

一。网上搜索的,看着靠谱,但是得删除数据库服务器重装 The above problem will be occured because the mysql-devel package is not properly installed in your system. I will be explain the same in Centos of how to fix it. When you try to install that package using,

yum install mysql-devel

somtimes there will be some clash occurs with the existing packages that gets installed if you install the MySql-Administrative tool and MySQL query browser.

In that case, you need to uninstall all the existing mysql2 packages and install it again.

rpm -qa -last | grep -i mysql
yum remove MySQL-server-5.5.27-1.rhel5
yum remove MySQL-client-5.5.27-1.rhel5
yum remove mysql-gui-tools-5.0r12-1rhel4
yum remove mysql-query-browser-5.0r12-1rhel4-a

So, you can uninstall whatever mysql things displayed with rpm -qa as like above.

Then you can install the mysql-server and mysql-client.

yum install mysql-server
yum install mysql-client

Now you do the installation of mysql-devel package.

yum install mysql-devel

Now there is no package clashes and you can able to install the mysql2 gem.

gem install mysql2 -v '0.3.11'

Now your mysql2 gem will be successfully installed and you are good to go.

http://stackoverflow.com/questions/3754662/errors-installing-mysql2-gem-via-the-bundler

二。不用重装,但不知道能不能行

wget http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-devel-5.5.27-1.el6.x86_64.rpm 

rpm -Uvh MySQL-devel-5.5.27-1.el6.x86_64.rpm 

gem install mysql 

gem install mysql2

http://stackoverflow.com/questions/12119567/mysql2-gem-installation-fails

看来都是一通乱搞呀! 错误不是很明显了吧:/usr/bin/ld: cannot find -lmysqlclient gem install 时指定 mysqlclient.so.X 的目录 或者试试: 将 Filename : /usr/lib64/mysql/libmysqlclient_r.a Filename : /usr/lib64/mysql/libmysqlclient.a Filename : /usr/lib64/mysql/libmysqlclient.so ... 等等 链接到 /usr/lib64/ 下

ubuntu 下 sudo apt-get install libmysqlclient-dev

ln -s /usr/lib64/mysql/libmysqlclient_r.a /usr/lib/mysql/libmysqlclient_r.a

道理上是说 32 位在默认路径下找不到 64 位的 lib,不过很少碰到了。

那么多复杂的东西 ... remove 掉相关 mysql 的东西 直接 mysql-devel

sudo yum install gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel
sudo yum install ruby-rdoc ruby-devel
sudo yum install mysql-devel

@chairy11 发现你安装的 mysql-libs 是 5.1.17 的版本,这个版本的 mysql-libs 和 Mysql 5.6 有冲突的。如果是 5.6 的需要移除 已安装关于 mysql-libs

sudo yum remove mysql-libs

如果是 5.6 的话应该安装的

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm/from/http://cdn.mysql.com/

rpm -ih MySQL-shared-5.6.15-1.el6.x86_64.rpm

还有就是可以看看 mysql2 issue https://github.com/brianmario/mysql2/issues/551

#15 楼 @gihnius 看来你的才是正解啊!

#19 楼 @floger 这个好深奥……暂时解决了,我就先不弄了吧……

#1 楼 @flowerwrong #3 楼 @floger #11 楼 @huacnlee #15 楼 @gihnius #16 楼 @googya #17 楼 @liwei78 #18 楼 @jhjguxin

谢谢各位:)

因为服务器上已经有别的项目在用 MySQL,我不敢像大家建议的那样先删除后安装什么的…… 结果我领导比较彪悍,直接暴力删除,然后把 gem mysql2 装上了,再恢复 mysql,发现又不行了。 最后,听说他把 libmysqlclient.a, libmysqlclient_r.a, libmysqlservices.a 放到 /usr/lib64下,就可以了…… 反正,现在是可以了,天都亮了!

再次谢谢各位朋友帮忙!非常感谢!

#15 楼 @gihnius 哎呀呀,又出错啦!说找不到 libmysqlclient_r.so,请问这个东东在哪里啊?或者我怎么才能让 gem 知道地址啊?

$ bin/rake db:migrate
rake aborted!
LoadError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory - /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/mysql2/mysql2.so
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `block in require'
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:232:in `load_dependency'
/usr/local/rvm/gems/ruby-2.1.2/gems/activesupport-4.1.7/lib/active_support/dependencies.rb:247:in `require'
/usr/local/rvm/gems/ruby-2.1.2/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
/usr/local/rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
/

#19 楼 @floger 555, 我现在提示说

$ bin/rake db:migrate
rake aborted!
LoadError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory - /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/mysql2/mysql2.so

有可能是你说的那个『 mysql-libs 是 5.1.17 的版本,和 Mysql 5.6 有冲突』的问题。 但我看不懂你这两句命令不太敢用啊……

sudo yum remove mysql-libs

会删除我现在的 5.1.17 的 lib?

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm/from/http://cdn.mysql.com/

rpm -ih MySQL-shared-5.6.15-1.el6.x86_64.rpm

只是安装匹配的 lib?

#23 楼 @chairy11 看看这个: ldd /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/mysql2/mysql2.so 链接的 lib 在什么目录. 之前那些文件是链接的还是移动 (mv) 的? 反正文件都在,放到正常的位置应该没问题的。

#25 楼 @gihnius 运行你这句结果是:

ldd /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/mysql2/mysql2.so
    linux-vdso.so.1 =>  (0x00007fff5bd47000)
    libruby.so.2.1 => /usr/local/rvm/rubies/ruby-2.1.2/lib/libruby.so.2.1 (0x00007f0a83f1e000)




    libmysqlclient_r.so.16 => not found




    libz.so.1 => /lib64/libz.so.1 (0x00007f0a83cfa000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0a83add000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f0a838a5000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f0a8368c000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f0a83408000)
    libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f0a8319b000)
    libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f0a82db8000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f0a82bb0000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f0a829ab000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f0a82618000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f0a845cb000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007f0a823b6000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f0a82171000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f0a81e8b000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f0a81c87000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f0a81a5a000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f0a8184f000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f0a8164b000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f0a81431000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f0a81212000)

看来我机子上应该是没有这个文件的。 之前的应该是复制过去的吧……

#26 楼 @chairy11 这个 libmysqlclient_r.so.16 => not found 在 /usr/lib64/mysql 有没有?没有的话就重新安装 mysql 吧,可能都被搞得一塌糊涂了。

#26 楼 @chairy11 这个 libmysqlclient_r.so.16 => not found 在 /usr/lib64/mysql 有没有?没有的话就重新安装 mysql 吧,可能都被搞得一塌糊涂了。

#28 楼 @gihnius 不敢重装了啊……昨天我领导重装了,今天跟我说,再也不帮我弄了……那个 mysql 上有别的项目在跑啊……我不能随便弄啊…… 而且昨天他复制那三个文件过去,好像说这样还是不好。能不能像你说的,gem install 时指定这些东西的目录?我不知道怎么指定呀……能帮我写个命令行吗?

#24 楼 @chairy11 是的那个删除命令,只会删除你当前版本 libs 那个安装命令就是告诉你要安装 对应版本的 libs 好像在 5.6 里移除 libmysqlclient 的 lib,放在 Mysql-share 里面了。 这个在 http://dev.mysql.com/doc/refman/5.6/en/linux-installation-rpm.html 有说明的 If you get a dependency failure when trying to install MySQL packages (for example, error: removing these packages would break dependencies: libmysqlclient.so.10 is needed by ...), you should also install the MySQL-shared-compat package, which includes the shared libraries for older releases for backward compatibility.

As of MySQL 5.6.5, the MySQL-shared-compat RPM package enables users of Red Hat-provided mysql--5.1 RPM packages to migrate to Oracle-provided MySQL--5.5 packages. MySQL-shared-compat replaces the Red Hat mysql-libs package by replacing libmysqlclient.so files of the latter package, thus satisfying dependencies of other packages on mysql-libs. This change affects only users of Red Hat (or Red Hat-compatible) RPM packages. Nothing is different for users of Oracle RPM packages.

我找了下,首先查找 libmysqlclient.so.16 文件,如果有就ldd,没有就安装他,如下: https://gettechgo.wordpress.com/2012/12/03/failed-dependency-libmysqlcliet-so-16/ 原文: While installing‘mysql’module for PHP 5.4 (yum install php54w-mysql*), I encountered the following error:

Missing Dependency: libmysqlclient.so.16(libmysqlclient_16) is needed by package php-mysql-package-version

The issue was due to the “Missing Dependency” and a library called “libmysqlclient.so.16″ was required.

To resolve this, I downloaded a “compat” rpm, and installed all the different versions of libmysqlclient.so.{12,14,15,16}:

Available at: http://downloads.mysql.com/archives/mysql-5.1/MySQL-shared-compat-5.1.49-1.rhel5.x86_64.rpm

wget "http://downloads.mysql.com/archives/mysql-5.1/MySQL-shared-compat-5.1.49-1.rhel5.x86_64.rpm"

rpm -ivh MySQL-shared-compat-5.1.49-1.rhel5.x86_64.rpm

After that, ‘mysql’ module got installed with PHP 5.4 properly.

#30 楼 @floger 555,好像不行,竟然说我没装 lib

$ sudo yum remove mysql-libs


Loaded plugins: fastestmirror, refresh-packagekit
Setting up Remove Process
No Match for argument: mysql-libs
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
Package(s) mysql-libs available, but not installed.
No Packages marked for removal

好像下面那个能下载成功,可是它为什么带着 redhat-package 的说法的?我用 centos 的哦,有针对性的吗?

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm/from/http://cdn.mysql.com/


--2014-10-31 06:31:36--  http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
正在解析主机 dev.mysql.com... 137.254.60.11
正在连接 dev.mysql.com|137.254.60.11|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://cdn.mysql.com/archives/mysql-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm [跟随至新的 URL]
--2014-10-31 06:31:36--  http://cdn.mysql.com/archives/mysql-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm
正在解析主机 cdn.mysql.com... 
23.41.85.226
正在连接 cdn.mysql.com|23.41.85.226|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1937596 (1.8M) [application/x-redhat-package-manager]
正在保存至: “index.html”

100%[====================================================================================================================>] 1,937,596   1.00M/s   in 1.8s    

2014-10-31 06:31:45 (1.00 MB/s) - 已保存 “index.html” [1937596/1937596])

但又安装不上:

$ rpm -ih MySQL-shared-5.6.15-1.el6.x86_64.rpm


error: open of MySQL-shared-5.6.15-1.el6.x86_64.rpm failed: 没有那个文件或目录

#31 楼 @flowerwrong 根据官方手册写的和我的版本 (MySQL-server-5.6.15-1.el6.x86_64, MySQL-client-5.6.15-1.el6.x86_64, MySQL-devel-5.6.15-1.el6.x86_64), 我觉得我需要安装 MySQL-shared-compat . 你给的解决方案我觉得对,但我觉得你给的版本应该改为 MySQL-shared-5.6.15-1.el6.x86_64.rpm,或者 MySQL-shared-compat-5.6.15-1.el6.x86_64.rpm。 我正在找匹配的地址。

#30 楼 @floger 我觉得你找的这个问题根源对了。但那个 wget 的地址好像不对,保存之后是一个网页。我试试找找新的地址哦!

#30 楼 @floger #31 楼 @flowerwrong

现在情况如下:

$ wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-shared-5.6.15-1.el6.x86_64.rpm

rpm -ih MySQL-shared-5.6.15-1.el6.x86_64.rpm
$ wget http://cdn.mysql.com/archives/mysql-5.6/MySQL-shared-compat-5.6.15-1.el6.x86_64.rpm

rpm -ih MySQL-shared-compat-5.6.15-1.el6.x86_64.rpm
$ rpm -qa|grep -i MySQL

MySQL-shared-5.6.15-1.el6.x86_64
MySQL-server-5.6.15-1.el6.x86_64
MySQL-client-5.6.15-1.el6.x86_64
MySQL-shared-compat-5.6.15-1.el6.x86_64
MySQL-devel-5.6.15-1.el6.x86_64

问题解决了!谢谢谢谢啊:)真的太好了!折腾了两三天!

需要 登录 后方可回复, 如果你还没有账号请 注册新账号