MySQL Tutorial (Termux)
3 minute read
Hello Everyone,
I hope you are doing well.I am using termux and mariadb here , you can use mysql community version.
So let's start ,
First I'm gonna install some packages.If any error happens while installing you can change repo in termux.
pkg update && pkg install proot mariadb
Now we gonna start SQL server,
mysqld_safe -u root
Create new tab & enter mysql
MariaDB [(none)]>
Now for creating new database
create database db_name;
Example:
MariaDB [(none)]> create database sqltut;
Query OK, 1 row affected (0.029 sec)
Let's Check data base created or not
show databases;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sqltut |
| test |
+--------------------+
5 rows in set (0.036 sec)
I got results like this, our database sucessfully created.
Here I'm choosing sqltut as my database
use sqltut;
MariaDB [(none)]> use sqltut;
Database changed
MariaDB [sqltut]>
As you can see my database selected from none to sqltut.
Now we gonna create table inside database,
show tables;
MariaDB [sqltut]> show tables;
Empty set (0.001 sec)
Now we gonna make table named persons with column ,
Id First-name last name address City
MariaDB [sqltut]> CREATE TABLE Persons (
-> ID int,
-> FirstName varchar(255),
-> LastName varchar(255),
-> Address varchar(255),
-> City varchar(255)
-> );
Query OK, 0 rows affected (0.057 sec)
Let's check our table created or not !
desc Persons;
MariaDB [sqltut]> desc Persons;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| ID | int(11) | YES | | NULL | |
| FirstName | varchar(255) | YES | | NULL | |
| LastName | varchar(255) | YES | | NULL | |
| Address | varchar(255) | YES | | NULL | |
| City | varchar(255) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
5 rows in set (0.006 sec)
SQL Operators:
1. OR
The OR operator displays a record if any of the conditions separated by OR is TRUE.
OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
Example:
The table below shows the complete "Members" table
ID Name Age Address Salary
1 Ali 32 Delhi 2000
2 Shyam 25 Kolkata 9000
3 Niket 23 Mumbai 6000
4 Kausar 25 Indore 4000
5 Sujal 27 Agra 8000
6 Suraj 22 Bengal 6000
7 Rameez 24 Assam 4000
SELECT * FROM Members
WHERE Address='Delhi' OR Address='Kolkata';
ID Name Age Address Salary
1 Ali 32 Delhi 2000
2 Shyam 25 Kolkata 9000
2. AND
The AND operator displays a record if all the conditions separated by AND are TRUE.
AND Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
Example:
ID Name Age Address Salary
1 Ali 32 Delhi 2000
2 Shyam 25 Kolkata 9000
3 Niket 23 Mumbai 6000
4 Kausar 25 Indore 4000
5 Sujal 27 Agra 8000
6 Suraj 22 Bengal 6000
7 Rameez 24 Assam 4000
SELECT * FROM Members
WHERE Address='Delhi' AND Salary='2000';
Result:
ID Name Age Address Salary
1 Ali 32 Delhi 2000
3. NOT
The SQL NOT Operators
The NOT operator displays a record if the condition(s) is NOT TRUE.
NOT Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
EXAMPLE:
The table below shows the complete "Members" table
ID Name Age Address Salary
1 Ali 32 Delhi 2000
2 Shyam 25 Kolkata 9000
3 Niket 23 Delhi 6000
4 Kausar 25 Indore 4000
5 Sujal 27 Delhi 8000
6 Suraj 22 Bengal 6000
7 Rameez 24 Delhi 4000
Example
SELECT * FROM Members
WHERE NOT Address='Delhi';
ID Name Age Address Salary
2 Shyam 25 Kolkata 9000
4 Kausar 25 Indore 4000
6 Suraj 22 Bengal 6000
Best app for complex database link
Regards, #androidgeek
Post a Comment