What is MySQL?

Mysql is a database management system, a tool that helps you interect with sql databases. A database is a collection of sql tables. Using mysql you can easily manage database tables, their permissions.

How to install mysql on ubuntu?

Ubuntu comes with default mysql repository incase you want to proceed with existing repository follow the steps below.

# update linux repos
sudo apt-get update

# install mysql-server default version
sudo apt-get install mysql-server

# install mysql 5.5
sudo apt-get install mysql-server-5.5

# install mysql 5.6
sudo apt-get install mysql-server-5.6

How to install mysql 5.7 on ubuntu?

If you do not want to install default version or 5.5/5.6 then to install 5.7 follow the steps below.

# install mysql package
wget http://dev.mysql.com/get/mysql-apt-config_0.6.0-1_all.deb

# extract the package
sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb

# update the package
sudo apt-get update

# install mysql 5.7
sudo apt-get install mysql-server

How to secure mysql server?

To secure the mysql you have to follow the steps below.

# to secure mysql server
# run following command
sudo mysql_secure_installation

How to create a database in mysql?

When you install a mysql server on linux you have to know following things:

  • hostname
  • port
  • credentials for root user

Once you have these stuff you can login to mysql server using ssh. Open your linux terminal window and try to ssh using above credentials:

# login to mysql 
# server using ssh
mysql -u root -p

# once you logged in
# run following command
# to create test database
mysql> create database test_db;

# grant a user to access this
# newly created database
mysql> create user 'user'@'localhost' identified by 'password';

# grant access for this user to database
mysql> grant all on test_db.* to 'user';

How to start/stop mysql on linux?

To start and stop mysql on ubuntu machine try following commands:

# start mysql server
sudo service mysql stop

# start mysql server
sudo service mysql start