Skip to content

Instantly share code, notes, and snippets.

@jebenexer
Forked from beaudierman/gist:5444977
Last active December 18, 2015 13:29
Show Gist options
  • Save jebenexer/5790236 to your computer and use it in GitHub Desktop.
Save jebenexer/5790236 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# I recently had to install MySQL 5.6 on Ubuntu 12.04 from a .deb package on the MySQL website. It seems that either the package has been updated recently or nobody uses this method to install so I ended up running into endless problems. Through trial and error I found the following method works for me.
#Install libaio-dev:
sudo apt-get install libaio-dev
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.12-debian6.0-x86_64.deb/from/http://cdn.mysql.com/ -O mysql-server.deb
#Now install your package(mine was enterprise edition, community may have a different filename):
sudo dpkg -i mysql-server.deb
#This will install your files to the /opt directory, instead of the more common /etc directory. No worries, all we need to do is point our system at this new directory.
#Run the following commands to set up the mysql user and group if you have never had mysql installed before. If you had a previous version installed, the user and group are already created.
sudo groupadd mysql
sudo useradd -r -g mysql mysql
#Move into the mysql directory and make a data directory.
cd /opt/mysql/server-5.6/
sudo mkdir data
sudo chown mysql:mysql data
#Now we can create and configure the database.
sudo scripts/mysql_install_db --user=mysql --language=/opt/mysql/server-5.6/share/english/
sudo cp support-files/my-default.cnf /etc/my.cnf
sudo cp support-files/mysql.server /etc/init.d/mysql.server
sudo cp support-files/mysql-log-rotate /etc/logrotate.d/mysql.server
#Before we start the server, let's make sure MySQL is only going to be using the one configuration file.
sudo rm /etc/mysql/my.cnf /opt/mysql/server-5.6/my.cnf
#Now let's start MySQL server.
sudo service mysql.server start
#All that's left is to set your PATH so that mysql is accessible from any location.
echo 'export PATH=$PATH:/opt/mysql/server-5.6/bin' | sudo tee /etc/profile.d/mysql.server.sh
#From this point you'll be able to log in to MySQL locally with any username you can think of - or no username at all.
# mysql -u anyusernameintheworld
if [ -f "$HOME/.profile" ]; then
. "$HOME/.profile"
fi
if [ -f "$HOME/.bash_profile" ]; then
. "$HOME/.bash_profile"
fi
#That's obviously very bad practice. Let's go ahead and add a password to the root useraccount and then create a username that we'll actually query with.
echo "please set a root passwd:"
read root_pw
user=$(whoami)
echo "please provide a new default user passwd"
read user_pw
echo "UPDATE mysql.user SET Password=PASSWORD('$root_pw') WHERE User='root';GRANT ALL ON *.* TO '$user'@'localhost' IDENTIFIED BY '$user_pw'; GRANT ALL ON *.* TO '$user'@'%' IDENTIFIED BY '$user_pw'; FLUSH PRIVILEGES;" | mysql
echo "[mysql]\nuser=$user\npass=$user_pw" >> ~/.my.cnf
#Please note that you can(and should) change % to be an IP address that you are connecting from. The % is a wildcare operator, so if you'd like everyone on your local network to connect you could use something like 192.168.%.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment