Skip to content

Instantly share code, notes, and snippets.

@huangqiheng
Forked from Jamp/build_mysql.sh
Last active March 1, 2024 06:59
Show Gist options
  • Save huangqiheng/7fbfcd7f4f97255447713ec6e9e85257 to your computer and use it in GitHub Desktop.
Save huangqiheng/7fbfcd7f4f97255447713ec6e9e85257 to your computer and use it in GitHub Desktop.
Build and install MySQL 5.1 from source on Ubuntu 18.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' \
CXXFLAGS="-Wno-narrowing -fpermissive"
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
@peconi
Copy link

peconi commented Mar 3, 2023

Thank you for this nice and concise script. Works like a charm on 20.04 as well.

I added this at the end so it auto starts:

sudo update-rc.d mysql defaults
systemctl enable mysql.service

If you get:
Failed to enable unit: Unit file /etc/systemd/system/mysql.service is masked.

Then one should do this:

systemctl unmask mysql.service
systemctl enable mysql.service

Thanks!

@bs135
Copy link

bs135 commented Feb 28, 2024

thank you so much

@llovvoll
Copy link

llovvoll commented Mar 1, 2024

it's worked, thank you

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