Here’s a short practice to help you get started with MySQL:
- Connect to the MySQL server using the MySQL command line tool.
- Create a new database named “practice_db” using the following command: “CREATE DATABASE practice_db;”
- Use the newly created database using the following command: “USE practice_db;”
- Create a new table named “students” with columns for “id”, “name”, “age”, and “email” using the following command: “CREATE TABLE students (id INT PRIMARY KEY, name VARCHAR(50), age INT, email VARCHAR(100));”
- Insert some data into the “students” table using the following commands:
sqlCopy codeINSERT INTO students (id, name, age, email) VALUES (1, 'John Doe', 22, 'johndoe@example.com');
INSERT INTO students (id, name, age, email) VALUES (2, 'Jane Doe', 20, 'janedoe@example.com');
INSERT INTO students (id, name, age, email) VALUES (3, 'Bob Smith', 25, 'bobsmith@example.com');
- Retrieve all data from the “students” table using the following command: “SELECT * FROM students;”
- Retrieve only the names and emails of students using the following command: “SELECT name, email FROM students;”
- Update the age of the student with id “2” to “21” using the following command: “UPDATE students SET age = 21 WHERE id = 2;”
- Delete the student with id “3” using the following command: “DELETE FROM students WHERE id = 3;”
These are the basic commands for working with a MySQL database. With these commands, you should be able to perform basic operations such as creating a database, tables, and inserting, retrieving, updating, and deleting data.