【问题标题】:can't install mysql2 on centos 7 with error of libmysqlclient [closed]无法在centos 7上安装mysql2,出现libmysqlclient错误[关闭]
【发布时间】:2018-12-27 04:17:44
【问题描述】:

当我通过gem安装mysql2时,遇到了一些困惑。我被困扰了2天。 我已经尝试了所有这些命令:

gem install mysql2 -v '0.5.1' --source 'https://gems.ruby-china.com/'  -- --with-mysql-lib="/usr/lib/mysql"
gem install mysql2 -v '0.5.1' --source 'https://gems.ruby-china.com/'  -- --with-mysql-lib="/usr/lib64/mysql"
gem install mysql2 -v '0.5.1' --source 'https://gems.ruby-china.com/'

但所有这些都以相同的错误返回给我,如下所示:

Building native extensions with: '--with-mysql-lib=/usr/lib/mysql'
This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.5.1/ext/mysql2
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20180719-13223-afd0n0.rb extconf.rb --with-mysql-lib=/usr/lib/mysql
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
Using mysql_config at /usr/bin/mysql_config
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... no
checking for MYSQL_OPT_SSL_ENFORCE in mysql.h... no
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... yes
Setting libpath to /usr/lib64/mysql
creating Makefile
current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.5.1/ext/mysql2
make "DESTDIR=" clean

current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/mysql2-0.5.1/ext/mysql2
make "DESTDIR="
compiling client.c
compiling result.c
compiling statement.c
statement.c: In function 'rb_raise_mysql2_stmt_error':
statement.c:47:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   VALUE rb_error_msg = rb_str_new2(mysql_stmt_error(stmt_wrapper->stmt));
   ^
statement.c:53:3: warning: ISO C90 forbenter code hereids mixed declarations and code [-Wdeclaration-after-statement]
   rb_encoding *default_internal_enc = rb_default`enter code here`_internal_encoding();
   ^
In file included from ./mysql2_ext.h:39:0,
                 from statement.c:1:
statement.c: In function 'rb_mysql_stmt_execute':
./client.h:22:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:261:3: note: in expansion of macro 'GET_CLIENT'
   GET_CLIENT(stmt_wrapper->client);
   ^
statement.c:389:13: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
             VALUE rb_val_as_string = rb_funcall(argv[i], intern_to_s, 0);
             ^
In file included from ./mysql2_ext.h:39:0,
                 from statement.c:1:
statement.c: In function 'rb_mysql_stmt_fields':
./client.h:22:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:491:3: note: in expansion of macro 'GET_CLIENT'
   GET_CLIENT(stmt_wrapper->client);
   ^
compiling mysql2_ext.c
compiling infile.c
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status
make: *** [mysql2.so] Error 1

make failed, exit code 2

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

这是我所有关于mysql的文件

【问题讨论】:

    标签: c ruby rubygems mysql2


    【解决方案1】:

    你缺少 mysqlclient。

    尝试按照此处的步骤操作:Ruby gem mysql2 install failing

    在 OSX 上,试试brew install mysql-connector-c

    最坏的情况你可能需要卸载 mysql 并重新安装它:https://github.com/brianmario/mysql2/issues/687#issuecomment-144811470

    【讨论】:

    • 非常感谢!我会试一试的!
    • 经过大量尝试,我发现我的centos默认仓库包含mariadb vision而不是mysql-comminity-client,所以它的lib不符合mysql2的要求。所以首先我卸载了我所有关于 mysql 的包。然后我将 mysql 社区存储库添加到我的 centos 存储库列表中。安装此版本 mysql-client 后,我​​成功安装了 mysql2 ruby​​ 包!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 2014-12-02
    • 2014-04-16
    • 1970-01-01
    相关资源
    最近更新 更多