This is an old revision of the document!
Perform Simple SQL Queries Against A Database
General Information
Basic SQL commands.
Lab Setup
The following virtual machines will be used:
- server1.example.com (192.168.1.150) → Perform any client testing here
- server2.example.com (192.168.1.151) → Install the database here
Basics of SQL: Connect and Navigate
Connect to the database
mysql -u root -p
Show databases on the system
MariaDB [(none)]> SHOW DATABASES;
Use a specific database called 'emails'
MariaDB [(none)]> USE emails;
Show the tables in the database, emails
MariaDB [emails]> SHOW TABLES;
Show the fields available in a table called 'users'
MariaDB [emails]> DESCRIBE users;
Basics of SQL: Add,Remove,Modify
Insert a new row/entry into a table
MariaDB [emails]> INSERT INTO users (userID,userFirstName,userLastName,userEmailAddress) VALUES (001,"Robert","Jones","robertjones@example.com");
Show all entries from the users table
MariaDB [emails]> SELECT * FROM users;
Show all entries from the users table where the last name equals “Smith”
MariaDB [emails]> SELECT * FROM users WHERE userLastName="Smith";
Delete the entry where the user id is 2
MariaDB [emails]> DELETE FROM users WHERE userID=2;
Update the entry of Jane Smith to change her last name and email address
MariaDB [emails]> UPDATE users SET userLastName="Jones",userEmailAddress="janejones@example.com" WHERE userID=2;