简体   繁体   English

为什么我不能安装 mysql2 gem?

[英]Why can't I install mysql2 gem?

My OS is Red Hat Enterprise Linux Server 7.4 (Maipo), CPU architecture is x86_64 and byte order is Little Endian.我的操作系统是 Red Hat Enterprise Linux Server 7.4 (Maipo),CPU 架构是 x86_64,字节顺序是 Little Endian。

I was doing bundle install for my rails application, but I get我正在为我的 rails 应用程序进行bundle install ,但我得到了

An error occurred while installing mysql2 (0.4.10), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/'` succeeds before bundling.

and doing gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/' gives me:并做gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/'给我:

Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /home/my-user-name/.rvm/gems/ruby-2.4.4/gems/mysql2-0.4.10/ext/mysql2
/home/my-user-name/.rvm/rubies/ruby-2.4.4/bin/ruby -r ./siteconf20180704-8600-mkihlj.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... 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... yes
checking for MYSQL.net.vio in mysql.h... no
checking for MYSQL.net.pvio in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
-----
Setting libpath to /usr/lib64/
-----
creating Makefile

current directory: /home/my-user-name/.rvm/gems/ruby-2.4.4/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR=" clean

current directory: /home/my-user-name/.rvm/gems/ruby-2.4.4/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR="
compiling client.c
In file included from ./mysql2_ext.h:35:0,
                 from client.c:1:
client.c: In function ‘rb_set_ssl_mode_option’:
./client.h:56:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
client.c:118:3: note: in expansion of macro ‘GET_CLIENT’
   GET_CLIENT(self);
   ^
client.c:119:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   int val = NUM2INT( setting );
   ^
client.c:145:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
client.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c: In function ‘rb_mysql_result_alloc_result_buffers’:
result.c:326:40: warning: assignment from incompatible pointer type [enabled by default]
     wrapper->result_buffers[i].is_null = &wrapper->is_null[i];
                                        ^
result.c:328:40: warning: assignment from incompatible pointer type [enabled by default]
     wrapper->result_buffers[i].error   = &wrapper->error[i];
                                        ^
result.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
compiling statement.c
statement.c: In function ‘rb_raise_mysql2_stmt_error’:
statement.c:50: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:57:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   rb_encoding *default_internal_enc = rb_default_internal_encoding();
   ^
In file included from ./mysql2_ext.h:35:0,
                 from statement.c:1:
statement.c: In function ‘execute’:
./client.h:56:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:273:3: note: in expansion of macro ‘GET_CLIENT’
   GET_CLIENT(stmt_wrapper->client);
   ^
statement.c:405: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:35:0,
                 from statement.c:1:
statement.c: In function ‘fields’:
./client.h:56:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   mysql_client_wrapper *wrapper; \
   ^
statement.c:481:3: note: in expansion of macro ‘GET_CLIENT’
   GET_CLIENT(stmt_wrapper->client);
   ^
statement.c: At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lmariadb
collect2: error: ld returned 1 exit status
make: *** [mysql2.so] Error 1

make failed, exit code 2

Gem files will remain installed in /home/my-user-name/.rvm/gems/ruby-2.4.4/gems/mysql2-0.4.10 for inspection.
Results logged to /home/my-user-name/.rvm/gems/ruby-2.4.4/extensions/x86_64-linux/2.4.0/mysql2-0.4.10/gem_make.out

I read this post ,我读了这篇文章

but doing sudo yum install mysql-devel gives:但是做sudo yum install mysql-devel会给出:

Loaded plugins: search-disabled-repos

Package MariaDB-devel-10.3.8-1.el7.centos.x86_64 already installed and latest version
Nothing to do

even though running sudo yum list installed mysql-devel gives:即使运行sudo yum list installed mysql-devel给出:

Loaded plugins: search-disabled-repos
Error: No matching Packages to list

This is strange.这很奇怪。

In before, I installed MariaDB by doing these 2 steps:之前,我通过执行以下两个步骤安装了 MariaDB:

Step 1:第1步:

sudo vi /etc/yum.repos.d/MariaDB.repo

The content of it is:它的内容是:

# MariaDB 5.5 RedHat repository list - created 2018-07-04 03:54 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Step 2:第2步:

sudo yum install MariaDB-server MariaDB-client

And I did start it: sudo service mysql start我确实启动了它: sudo service mysql start

How can I install mysql2 gem successfully?如何成功安装mysql2 gem?

First run第一次运行

sudo apt-get install libmysqlclient-dev

Or或者

yum install mysql-devel

then然后

bundle install

I just had the same problem and this answer on a mysql2 issue worked for me.我刚刚遇到了同样的问题, 这个关于 mysql2 问题的答案对有用 Installing mysql-devel did not work for me.安装mysql-devel没有为我工作。

Their answer and what worked for me … yum install MariaDB-shared .他们的回答以及对我yum install MariaDB-shared …… yum install MariaDB-shared

Addendum: I was installing mysql2 v0.5.2 along side MariaDB 10.3.9.附录:我在 MariaDB 10.3.9 旁边安装了 mysql2 v0.5.2。

To intall gem mysql2 in a rail project on a mac you need mariadb-connector-c to compile it.要在 Mac 上的 Rail 项目中安装 gem mysql2,您需要 mariadb-connector-c 来编译它。

A bit off topic but for mac users with homebrew if libmysqlclient-dev doesn't work you can do:有点离题,但对于使用自制软件的 mac 用户,如果 libmysqlclient-dev 不起作用,您可以执行以下操作:

    brew unlink mariadb    
    brew install mariadb-connector-c    

    # cd into the rails project directory    

    bundle install (or gem install mysql2)    
    brew uninstall mariadb-connector-c    
    brew link mariadb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM