Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue

Any reason why this error popped up when I tried bundling an application: I have tried installing gem install mysql2 -v '0.3.21' as they recommend but it cant install properly. Also I am running this on macOS High Sierra. Sorry for my bad wording for this question because its my first time working with ruby.

 To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.0/mysql2-0.3.21/mkmf.log

current directory: /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling infile.c
compiling client.c
client.c:439:3: error: use of undeclared identifier 'my_bool'
  my_bool res = mysql_read_query_result(client);
  ^
client.c:441:19: error: use of undeclared identifier 'res'
  return (void *)(res == 0 ? Qtrue : Qfalse);
                  ^
client.c:762:3: error: use of undeclared identifier 'my_bool'
  my_bool boolval;
  ^
client.c:793:7: error: use of undeclared identifier 'boolval'
      boolval = (value == Qfalse ? 0 : 1);
      ^
client.c:794:17: error: use of undeclared identifier 'boolval'
      retval = &boolval;
                ^
client.c:797:10: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
    case MYSQL_SECURE_AUTH:
         ^~~~~~~~~~~~~~~~~
         MYSQL_DEFAULT_AUTH
/usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
client.c:798:7: error: use of undeclared identifier 'boolval'
      boolval = (value == Qfalse ? 0 : 1);
      ^
client.c:799:17: error: use of undeclared identifier 'boolval'
      retval = &boolval;
                ^
client.c:830:38: error: use of undeclared identifier 'boolval'
        wrapper->reconnect_enabled = boolval;
                                     ^
client.c:1185:38: error: use of undeclared identifier 'MYSQL_SECURE_AUTH'; did you mean 'MYSQL_DEFAULT_AUTH'?
  return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
                                     ^~~~~~~~~~~~~~~~~
                                     MYSQL_DEFAULT_AUTH
/usr/local/Cellar/mysql/8.0.11/include/mysql/mysql.h:188:3: note: 'MYSQL_DEFAULT_AUTH' declared here
  MYSQL_DEFAULT_AUTH,
  ^
10 errors generated.
make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/gems/mysql2-0.3.21 for inspection.
Results logged to /Users/yamanshrestha/Desktop/Dorsata/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-17/2.3.0/mysql2-0.3.21/gem_make.out

An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.21' --source 'http://rubygems.org/'` succeeds before bundling.
like image 968
yaman shrestha Avatar asked Jun 28 '18 18:06

yaman shrestha


4 Answers

For ubuntu this one helped me:

sudo apt-get -f install
sudo apt-get update
sudo apt-get install libmysqlclient-dev
bundle install

I've found this one here https://github.com/brianmario/mysql2/issues/445

like image 179
Rammgarot Avatar answered Oct 17 '22 03:10

Rammgarot


Fix by downgrade my mysql. And compile mysql2 using mysql v5.7.

For Mac users:

brew install [email protected]

gem install mysql2 -v '0.3.21' -- --with-mysql-include=/usr/local/Cellar/[email protected]/5.7.25/include/mysql --with-mysql-lib=/usr/local/Cellar/[email protected]/5.7.25/lib

Reference: https://github.com/brianmario/mysql2#configuration-options

like image 29
Tina Chen Avatar answered Oct 17 '22 04:10

Tina Chen


So, I managed to solve the problem by myself after looking around a bit. Basically, the version of the mysql2 that was written in the gemfile was outdated compared to the code written, therefore the difference in syntax between versions were causing this error when trying to install mysql2. Therefore to solve this you have to go to your gemfile and then change the version number for mysql2. I changed mines to the following:

 gem 'mysql2', '~> 0.4.10'

save the file and try installing again and it should worl

like image 33
yaman shrestha Avatar answered Oct 17 '22 04:10

yaman shrestha


For me the solution was to install mysql-connector-c, brew install mysql-connector-c. In my particular case it was already installed but I had to re-link it with force overwrite (the messages in the console will tell you exactly what to do in your situation).

like image 33
Julia Jacobs Avatar answered Oct 17 '22 04:10

Julia Jacobs