Skip to content

Instantly share code, notes, and snippets.

@Jamp
Forked from shichao-an/build_mysql.sh
Last active November 14, 2023 17:19
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save Jamp/7b6aa391f4dcdc738b89391de2a8aa6f to your computer and use it in GitHub Desktop.
Save Jamp/7b6aa391f4dcdc738b89391de2a8aa6f to your computer and use it in GitHub Desktop.
Build and install MySQL 5.1 from source on Ubuntu 16.04
#!/bin/bash
# Run as root
set -e
apt-get update
apt-get install -y build-essential
apt-get install -y libncurses5-dev
useradd mysql
cd
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
tar xzvf mysql-5.1.73.tar.gz
cd mysql-5.1.73
./configure \
'--prefix=/usr' \
'--exec-prefix=/usr' \
'--libexecdir=/usr/sbin' \
'--datadir=/usr/share' \
'--localstatedir=/var/lib/mysql' \
'--includedir=/usr/include' \
'--infodir=/usr/share/info' \
'--mandir=/usr/share/man' \
'--with-system-type=debian-linux-gnu' \
'--enable-shared' \
'--enable-static' \
'--enable-thread-safe-client' \
'--enable-assembler' \
'--enable-local-infile' \
'--with-fast-mutexes' \
'--with-big-tables' \
'--with-unix-socket-path=/var/run/mysqld/mysqld.sock' \
'--with-mysqld-user=mysql' \
'--with-libwrap' \
'--with-readline' \
'--with-ssl' \
'--without-docs' \
'--with-extra-charsets=all' \
'--with-plugins=max' \
'--with-embedded-server' \
'--with-embedded-privilege-control'
make
make install
mkdir -p /etc/mysql
mkdir -p /var/lib/mysql
mkdir -p /etc/mysql/conf.d
echo -e '[mysqld_safe]\nsyslog' > /etc/mysql/conf.d/mysqld_safe_syslog.cnf
cp /usr/share/mysql/my-medium.cnf /etc/mysql/my.cnf
sed -i 's#.*datadir.*#datadir = /var/lib/mysql#g' /etc/mysql/my.cnf
chown mysql:mysql -R /var/lib/mysql
mysql_install_db --user=mysql
mysqld_safe -user=mysql &
/usr/bin/mysql_secure_installation
cp /usr/share/mysql/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
update-rc.d mysql defaults
@bigornoo
Copy link

Hi, you can add that (if directory already exists) :
chown mysql:root /var/run/mysqld/

@dasiolacerda
Copy link

How do I solve this problem?

mysql.cc: In function ‘void build_completion_hash(bool, bool)’:
mysql.cc:2669:37: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
field_names[i][num_fields*2]= '\0';
^~~~
thanks

@hoangbits
Copy link

in step: /usr/bin/mysql_secure_installation if you got stuck:

you can apply these command the goes back:

chown mysql:mysql -R /var/lib/mysql

sudo chmod -R 755 /var/lib/mysql/

sudo service mysql start

@gajerajimesh
Copy link

I also got same issue,

mysql.cc: In function ‘void build_completion_hash(bool, bool)’:
mysql.cc:2669:37: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
field_names[i][num_fields*2]= '\0';
^~~~

@yohio
Copy link

yohio commented May 3, 2019

anyone solved this issue:

mysql.cc: In function ‘void build_completion_hash(bool, bool)’:
mysql.cc:2687:37: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
field_names[i][num_fields*2]= '\0';
^~~~
Makefile:825: recipe for target 'mysql.o' failed

@andrestoga
Copy link

I'm having the same issue:

mysql.cc: In function ‘void build_completion_hash(bool, bool)’:
mysql.cc:2687:37: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
field_names[i][num_fields*2]= '\0';
^~~~
Makefile:825: recipe for target 'mysql.o' failed
make[2]: *** [mysql.o] Error 1
make[2]: Leaving directory '/home/andrestoga/mysql-5.1.73/client'
Makefile:556: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/andrestoga/mysql-5.1.73/client'
Makefile:495: recipe for target 'all-recursive' failed

@muhamadksp
Copy link

I'm having the same issue:

mysql.cc: In function ‘void build_completion_hash(bool, bool)’:
mysql.cc:2687:37: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
field_names[i][num_fields*2]= '\0';
^~~~
Makefile:825: recipe for target 'mysql.o' failed
make[2]: *** [mysql.o] Error 1
make[2]: Leaving directory '/home/andrestoga/mysql-5.1.73/client'
Makefile:556: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/andrestoga/mysql-5.1.73/client'
Makefile:495: recipe for target 'all-recursive' failed

Any one can solving this problem?

@wam
Copy link

wam commented Sep 7, 2019

To solve the "invalid conversion" error problem, try running configure with CXXFLAGS="-fpermissive"

./configure --some-flag=whatever --another-flag=something CXXFLAGS="-fpermissive"
make
make install

Note for anyone who found this by googling, who might not be very familiar with compiling things: --some-flag=whatever --another-flag=something are not real flags, just examples. You would replace them with real flags, such as --prefix=/usr or anything else you want. Refer to the documentation/instructions you were reading about how to install an ancient version of mysql before you got sucked into researching this error.

Bonus

Once you've fixed that error, the compiler will be able to get further along, and you're likely to get another error about "narrowing", something like:

mysql.cc:1565:1: error: narrowing conversion of ‘18446744073709551615’ from ‘long unsigned int’ to ‘longlong’ {aka ‘long long int’} inside { } [-Wnarrowing]

It can be fixed by adding -Wno-narrowing to your CXXFLAGS. The whole thing would be

CXXFLAGS="-Wno-narrowing -fpermissive"

If you're using this build_mysql.sh script, you can edit it so that those options are on the last line of the configure command:

'--with-embedded-server' \
'--with-embedded-privilege-control' \
CXXFLAGS="-Wno-narrowing -fpermissive"
make
make install

In fact, it appears that there's a fork of the script that does exactly that:

https://gist.github.com/huangqiheng/7fbfcd7f4f97255447713ec6e9e85257

A Word of Caution

In the above examples, I've said that this "fixes" the problems. It actually just tells the compiler to ignore them. That's not great, but for many people it will suffice.

Other Possible Solutions

You could configure with -std=gnu++98:

./configure blah-blah-blah CXXFLAGS="-std=gnu++98"

https://admin-pain.blogspot.com/2019/04/install-mysql-version-under-ubuntu.html

Or, for just the conversion error, you could patch mysql.cc:

https://git.busybox.net/buildroot/commit/?id=94bad4fbf5759302a9f8f33267989d543f3a1167

@RayNawara
Copy link

Probably a stupid question but what directory should I be in to start this script? Anywhere special? Any one place better than another?

Thanks!

@wam
Copy link

wam commented Sep 30, 2019

@RayNawara it doesn't particularly matter, because on line 11, it executes cd with no arguments, which will change to the home directory of whatever user you're logged in as (likely /root if you're running as root per the usage instructions on line 2) and it will do the remaining tasks from there.

@wam
Copy link

wam commented Jul 21, 2021

@predators46 I think your problem is related to openwrt and gcc, not only mysql. I see you already tried asking on the openwrt forum and received no answers.

It looks like solution above ("patch mysql.cc") allowed you to get past the "narrowing conversion" error, but now you have a different problem. I don't know the answer, but try searching the web for "undefined reference to __sync_fetch_and_add_8". You are on a special journey, good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment