MySQL
CS 240: Advanced Software Construction
History
Installation
MySQL Community Server
https://dev.mysql.com/downloads/mysql/
MySQL Client Shell (console interface)
https://dev.mysql.com/downloads/shell/
Administration
Article explaining how to start, stop, and restart MySQL on Linux, Windows, and Mac
Console Client
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 |
GUI Client (Workbench)
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; |
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'; |