Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Build and install MySQL 5.1 from source on Ubuntu 14.04
# Run as root
set -e
apt-get update
apt-get install -y build-essential
apt-get install -y libncurses5-dev
useradd mysql
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' \
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
mysqld_safe -user=mysql &
cp /usr/share/mysql/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
update-rc.d mysql defaults
Copy link

flduce commented Nov 26, 2015

Thanks a lot for your work!

Copy link

mxwn commented May 24, 2016

Thanks for this script, it's helped me a lot. However it gets stuck at line 55 because it's missing the privilege tables and can't start the server, as evident from /var/lib/mysql/hostname.err.

Fix: run mysql_install_db --user=mysql --ldata=/var/lib/mysql/ just before starting the mysql server with mysqld_safe -user=mysql &.

Copy link

squarism commented Oct 5, 2016

@mxwn same thing, thanks for the reminder. 🌻

Copy link

VireshMathapati13 commented Dec 2, 2016

If I use above commands for Ubuntu 12.04, do they work ?

Copy link

HadesD commented Jan 5, 2017

Thanks for this

Copy link

loweehahn commented Feb 8, 2017

I'm prompted to enter the current root password for MySQL server which I don't know. Is there a default password or does anyone know what's the password?

Copy link

dejibimbolaAyo commented Feb 22, 2017

Please after running the script i ended up with this version of mysql:
mysql Ver 14.14 Distrib 5.7.17, for Linux (x86_64) using EditLine wrapper

my intent was to get an older version of MySql 5.1.73....
is there something that could have caused that.....?

N.B the installation was run on a virtual machine that had no previous installation of mysql....

Copy link

cs-chandu commented May 2, 2017

how to login to console and setup databases?

Copy link

sharma-rajendra commented Jun 14, 2017

Facing below error while run "make"

Making install in cmd-line-utils
make[1]: Entering directory /root/mysql-5.1.65/cmd-line-utils' Making install in readline make[2]: Entering directory /root/mysql-5.1.65/cmd-line-utils/readline'
gcc -DMYSQL_CLIENT_NO_THREADS -DHAVE_CONFIG_H -DNO_KILL_INTR -D_GNU_SOURCE=1 -I. -I../../include -I../../include -I../../include -I../.. -g -O2 -DUNIV_LINUX -DUNIV_LINUX -MT tilde.o -MD -MP -MF .deps/tilde.Tpo -c -o tilde.o tilde.c
In file included from tilde.c:55:0:
xmalloc.h:29:31: fatal error: readline/rlstdc.h: No such file or directory

include <readline/rlstdc.h>


compilation terminated.
make[2]: *** [tilde.o] Error 1
make[2]: Leaving directory /root/mysql-5.1.65/cmd-line-utils/readline' make[1]: *** [install-recursive] Error 1 make[1]: Leaving directory /root/mysql-5.1.65/cmd-line-utils'
make: *** [install-recursive] Error 1

Copy link

quangtt commented Jul 3, 2017

@shichao-an Hi you should update your gist by @mxwn suggestion, it worked for me. Thank both of you!

Copy link

netsys-it commented Jan 19, 2018

@induraj hello, i fixed this, problem is in file /root/mysql-5.1.65/cmd-line-utils/readline/xmalloc.h on 29 line, edit it to include "rlstdc.h", not include <readline/rlstdc.h>, that fixed my problem.

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