We can use the mysql utility for basic authentication and interaction with the MSQL database
mysql -u root -h <IP> -P 3306 -p
Queries must end with ;
Create a Database
CREATE DATABASE users;
Show all Databases and Use A Databases
SHOW DATABASES;
USE users;
A data type defines what kind of value a column may hold. Can consist from numbers, strings, date, time.
Show all Tables
Show Table Structure
With the DESCRIBE keyword we can see the table structure
Used to add new records a table
Allows us get data from a tables
Retrieves the user table where their id = 1
Remove tables and databases from the server
Change table name and fields
Update table properties
We can control the output of our results and sort them with the following keywords;
It's also possible to change the order from ascending to descending
Limits the number of items returned
Filte for specific data based on a condition
for example
WHERE name = rod
WHERE id < 5
Used to match a certain pattern
The % acts as wildcard and will match all characters after it.
The _ symbol is used to match exactly one character.
Allows us to use mutiple conditions at once
Takes two condition and return true or false based on the outcome.
Takes two expressions and returns true when at least one is true
Toggle between a boolean value
Symbol Operators
AND, NOT and OR can be represented as &&, II and !
Basic SQL queries
Union SQL query;
Retrieves a table containing a row with the user's information (where their id = 5) and all usernames and credit card numbers from accounts.
If we have a query that gets an item based in the $id:
We can change it to:
Since this will always be true, we should get back all the items in the products table!
We can also use this in a UNION: