Skip to content

Mysql

MySQL#

Table of Contents

Install#

1
sudo apt install mysql-server

Run#

1
sudo mysql -u root -p  #default password for root is "password"

if you get :

1
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

then check

1
service mysql start

Default password for root is: password

Help#

1
2
3
4
5
mysql> help;

or

\h

chage root password#

1
sudo mysqladmin password <new password>

Database#

Install test_db#

  • sakila
  • employees
  • source: https://github.com/toransahu/test_db

Install Sakila db prepared by mysql#

1
2
3
4
5
wget http://downloads.mysql.com/docs/sakila-db.tar.gz
tar -xzf sakila-db.tar.gz
cd sakila-db
mysql -u root -p < sakila-schema.sql
mysql -u root -p < sakila-data.sql

GRANTS#

1
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';

To see databases#

1
mysql> show databases;

To create a database#

1
2
3
mysql> create database <db_name>;

Query OK, 1 row affected (0.00 sec)

To use a database#

1
mysql> use <db_name>;

Tables#

To see tables#

1
show tables;

Subprograms#

Aggregation Functions#

Analytical Functions#

  • MySQL doesn't have Analytical Functions
    • while it is in
      • MSSQL
      • Oracle
      • PostgreSQL
      • MariaDB

Window Function#

over()