Step 1 — Installing MySQL
On Ubuntu 20.04, you can install MySQL using the APT package repository. At the time of this writing, the version of MySQL available in the default Ubuntu repository is version 8.0.27.
To install it, update the package index on your server if you’ve not done so recently:
sudo apt update
Then install the mysql-server package:
sudo apt install mysql-server
Ensure that the server is running using the systemctl start command:
sudo systemctl start mysql.service
First, open up the MySQL prompt:
sudo mysql
Add a database called books, enter:
CREATE DATABASE books;
Now, database is created. Use a database with use command, type:
USE books;
Next, create a table called authors with name, email and id as fields:
CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));
To display your tables in books database, enter:
SHOW TABLES;
Sample outputs:
+-----------------+
| Tables_in_books |
+-----------------+
| authors |
+-----------------+
1 row in set (0.00 sec)
Finally, add a data i.e. row to table books using INSERT statement, run:
INSERT INTO authors (id,name,email) VALUES(1,"Vivek","[email protected]");
Sample outputs:
Query OK, 1 row affected (0.00 sec)
Try to add few more rows to your table:
NSERT INTO authors (id,name,email) VALUES(2,"Priya","[email protected]");
NSERT INTO authors (id,name,email) VALUES(3,"Tom","[email protected]");
To display all rows i.e. data stored in authors table, enter:
SELECT * FROM authors;
Sample outputs:
+------+-------+---------------+
| id | name | email |
+------+-------+---------------+
| 1 | Vivek | [email protected] |
| 2 | Priya | [email protected] |
| 3 | Tom | [email protected] |
+------+-------+---------------+
3 rows in set (0.00 sec)
Now, you know how to create a database and a table.
install mysql on ubuntu how install mysql workbench on ubuntu how to install mysql on ubuntu how install mysql in linux how install mysql server in linux step by step