It’s MariaDB nowadays, but people still call it MySQL.
Just built a virtual server for databases, need of MySQL and just can’t find the notepad with commands – or better yet, no memo at all? the internet is full of tutorials, but heck, just needing the commands.
First, login as root with
sudo su -. Now, let’s add the repository key.
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
Then, let’s install the packages which allows us to use
apt-get install software-properties-common
Now we can add the repository.
add-apt-repository 'deb [arch=amd64,i386] http://mirror.netinch.com/pub/mariadb/repo/10.1/ubuntu trusty main'
Then we update the packages and start installing.
apt-get update && sudo apt-get -y install mariadb-server mariadb-client
It will ask you to create a root password, so give it to the setup twice. Remember to use a secure password. Now we need some configuring. Let’s backup the default config first.
cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
Then edit the config.
You will want to tune up
max_connections (for me the suitable amount is 300), and comment out
bind-address. Then you can just start the MySQL server:
service mysql start
Now you can try to login with your root password, with this command:
mysql -u root -p
If you get in, you can start creating your databases. For example, if I want a database for myexampleblog, I’d add it this way
CREATE USER 'myexampleusername'@'192.168.0.5' IDENTIFIED BY 'yourcomplicatedpassword'; GRANT ALL PRIVILEGES ON myexampledatabasename.* TO 'myexampleusername'@'192.168.0.5'; FLUSH PRIVILEGES;
The username, password and IP address are naturally free to choose. You can use either user your web server machine IP or allow all. If (for some reason, for example, local shared development) you want your database to be accessible from anywhere, make sure you have other security measures taken care of.
To do this, edit
bind-address and add your server’s public IP to it. Then, add a user like this:
CREATE USER 'myexampleusername'@'%' IDENTIFIED BY 'mycomplicatedpassword'; GRANT ALL PRIVILEGES ON *.* TO 'myexampleusername'@'%'; FLUSH PRIVILEGES;
Then quit with
^C or by typing
\q. You should now be good to go and connect your applications or WordPress or anything to the database with username, server IP, database name and password. I prefer Sequel Pro for viewing the databases.
Want to write with me?
Do you know something about tech, nerdy stuff, movies, code, AI, Internet phenomena, social media or anything related to geeky subjects? Join and write with me! I'm currently doing this alone and my time is not sufficient for upkeeping the blog by myself, so all pieces of articles are welcome. Contact me and get your user account.