SQL (Structured Query Language) is a universal language for managing relational databases. It allows you to create, modify, populate, and query tables. A DBMS (Database Management System) is the software that stores and provides access to data (e.g., MySQL, MariaDB, PostgreSQL, SQLite).
sudo apt-get install mysql-server
mysql -u root -p
CREATE DATABASE db_name; — create a new database.USE db_name; — select a database to work with.CREATE TABLE ... — create a table with specified fields and types.SHOW TABLES; — list all tables.DESCRIBE table_name; — show the structure of a table.INSERT INTO ... VALUES (...); — insert a record.SELECT ... FROM ...; — query data.UPDATE ... SET ... WHERE ...; — modify data by condition.DELETE FROM ... WHERE ...; — delete records by condition.LOAD DATA LOCAL INFILE ... INTO TABLE ...; — import data from a file.JOIN, ORDER BY, GROUP BY — join, sort, and group data.mysql -u root -p CREATE DATABASE cars; USE cars; CREATE TABLE new ( id INT AUTO_INCREMENT PRIMARY KEY, brand VARCHAR(10), model VARCHAR(10), year YEAR, price INT ); CREATE TABLE used ( id INT AUTO_INCREMENT PRIMARY KEY, brand VARCHAR(10), model VARCHAR(10), year YEAR, price INT ); SHOW TABLES; DESCRIBE new; EXIT;
new.txt with tab-separated values:KIA CERATO 2014 780000
mysql --local-infile=1 -u username -pUSE cars;LOAD DATA LOCAL INFILE "new.txt" INTO TABLE new;
SELECT * FROM new;
INSERT INTO new (brand, model, year) VALUES ('Daewoo', 'Nexia', 2015);
DELETE FROM new WHERE model = 'Matiz';
UPDATE new SET model = 'KUGA' WHERE model = 'FOCUS';
SELECT * FROM new; — select all records from the table.SELECT model FROM new; — select only the model column.SELECT * FROM new WHERE brand = "KIA"; — select all records where brand is KIA.SELECT * FROM new WHERE brand = "KIA" AND year = 2015; — with multiple conditions.SELECT * FROM new JOIN used ON new.brand = used.brand; — join records where brand matches (JOIN).SELECT * FROM new ORDER BY price; — sort by price.SELECT * FROM new GROUP BY brand; — group by brand.