1 of 9

MySQL

CS 240: Advanced Software Construction

2 of 9

History

  • 1995 released - Axmark, Larsson, and Widenius
  • 2008 Sun purchases ($1B)
  • 2010 Oracle acquires Sun
    • Widenius creates MariaDB fork
  • 2019 DBMS of the year

3 of 9

Installation

MySQL Community Server

https://dev.mysql.com/downloads/mysql/

MySQL Client Shell (console interface)

https://dev.mysql.com/downloads/shell/

4 of 9

Administration

Article explaining how to start, stop, and restart MySQL on Linux, Windows, and Mac

https://phoenixnap.com/kb/start-mysql-server

5 of 9

Console Client

6 of 9

Console Client Commands

Command

Purpose

Example

mysql -u <username> -p

Login to the shell

mysql -u root -p

help or ?

Get help

?

connect <connecton URL>

Connect to MySQL server

connect user@locahost:33060

sql

Change to SQL mode

sql

use <name>

Open database

use student

quit

Exit MySQL client

quit

7 of 9

GUI Client (Workbench)

8 of 9

SQL Commands (1)

Command

Purpose

Example

show databases

Lists all of the databases

show databases;

show tables

Lists all of the tables for the currently selected database

show tables;

describe <name>

List fields for a table

describe student;

show index from <name>

List indexes for a table

show index from student;

show full processlist

List currently executing queries

show full processlist;

create database <name>

Create a new database

create database student;

drop database <name>

Delete a database

drop database student;

9 of 9

SQL Commands (2)

Command

Purpose

Example

create table <name>

Create a new table

create table pet (name varchar(128), age int);

insert into <name>

Insert data into a table

insert into pet values ("zoe", 3);

select * from <name>

Query a table

select * from pet;

drop table <name>

Delete a table

drop table pet;

create user ‘<username>’@’<host>’ identified by ‘<password>’

Create a new database user

create user 'jerodw'@'localhost' identified by 'mypassword';

grant <permission> on <resource> to ‘<username>’@’<host>’

Grant access permissions to a user

grant all on BookClub.* to 'jerodw'@'localhost';