I have been trying to install mysql2 gem version 0.3.21
on my Ubuntu 20.04 but get the following error.
Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.
current directory: /home/user/.rvm/gems/ruby-2.5.3/gems/mysql2-0.3.21/ext/mysql2
/home/user/.rvm/rubies/ruby-2.5.3/bin/ruby -I /home/user/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0 -r ./siteconf20210822-101581-13t36qj.rb extconf.rb
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
-----
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/lib/x86_64-linux-gnu
-----
creating Makefile
current directory: /home/user/.rvm/gems/ruby-2.5.3/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean
current directory: /home/user/.rvm/gems/ruby-2.5.3/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling client.c
client.c: In function ‘nogvl_read_query_result’:
client.c:439:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
439 | my_bool res = mysql_read_query_result(client);
| ^~~~~~~
| bool
client.c: In function ‘_mysql_client_options’:
client.c:762:3: error: unknown type name ‘my_bool’; did you mean ‘bool’?
762 | my_bool boolval;
| ^~~~~~~
| bool
client.c:797:10: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean ‘MYSQL_DEFAULT_AUTH’?
797 | case MYSQL_SECURE_AUTH:
| ^~~~~~~~~~~~~~~~~
| MYSQL_DEFAULT_AUTH
client.c:797:10: note: each undeclared identifier is reported only once for each function it appears in
client.c: In function ‘set_secure_auth’:
client.c:1185:38: error: ‘MYSQL_SECURE_AUTH’ undeclared (first use in this function); did you mean ‘MYSQL_DEFAULT_AUTH’?
1185 | return _mysql_client_options(self, MYSQL_SECURE_AUTH, value);
| ^~~~~~~~~~~~~~~~~
| MYSQL_DEFAULT_AUTH
client.c:1186:1: warning: control reaches end of non-void function [-Wreturn-type]
1186 | }
| ^
client.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
make: *** [Makefile:242: client.o] Error 1
make failed, exit code 2
So far I have followed other solutions in other similar questions on Stackoverflow like installing default-libmysqlclient-dev
libmysqlclient-dev
but no luck so far.
My MySQL server version is 5.7.35
Maybe try this:
sudo apt remove libmysqlclient-dev
and
sudo apt install libmariadb-dev
The reason for the problem is that you have installed an incompatible version of the libmysqlclient-dev package, which by default in Ubuntu 20.04 corresponds to MySQL 8.0
Just you'll need to remove the installed version and install the appropriate one as follows bellow.
Consider I tried for the version I have MySQL 5.7.39, but you could find 5.7.35 in other repositories; here one: http://repo.mysql.com/apt/ubuntu/pool/mysql-5.7/m/mysql-community
Remove current installed:
sudo apt-get remove libmysqlclient-dev
Download and install with dependency package using dpkg -i
wget http://mirrors.kernel.org/ubuntu/pool/main/m/mysql-5.7/libmysqlclient-dev_5.7.39-0ubuntu0.18.04.2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/m/mysql-5.7/libmysqlclient20_5.7.39-0ubuntu0.18.04.2_amd64.deb
sudo dpkg -i libmysqlclient20_5.7.39-0ubuntu0.18.04.2_amd64.deb
sudo dpkg -i libmysqlclient-dev_5.7.39-0ubuntu0.18.04.2_amd64.deb
I solved the issue. I ran the following command
gem install mysql2 -v '0.3.21' -- --srcdir=/var/lib/mysql
where srcdir is pointing to the local installation of mysql.
Thanks. The answer above helped me. Only at first I had to find out where my mysql
which mysql
/usr/bin/mysql
gem install mysql2 -v '0.3.21' -- --srcdir=/usr/bin/mysql
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.