0% found this document useful (0 votes)
25 views

Day 1 Mysql Database Lesson

The document shows the steps of connecting to a MariaDB database using MySQL, creating a database and table, inserting data, and performing operations like selecting, updating, and deleting data. Key steps include connecting to MariaDB, creating a database called db_mhs and a table called mhs with various columns, inserting sample data, and deleting a row based on primary key.

Uploaded by

Teguh Pambudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Day 1 Mysql Database Lesson

The document shows the steps of connecting to a MariaDB database using MySQL, creating a database and table, inserting data, and performing operations like selecting, updating, and deleting data. Key steps include connecting to MariaDB, creating a database called db_mhs and a table called mhs with various columns, inserting sample data, and deleting a row based on primary key.

Uploaded by

Teguh Pambudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Microsoft Windows [Version 10.0.22000.

1219]

(c) Microsoft Corporation. All rights reserved.

C:\Users\teguh>cd c:/

c:\>cd xampp/mysql/bin

c:\xampp\mysql\bin>mysql -u root -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 10

Server version: 10.4.25-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| phpmyadmin |

| test |

+--------------------+

5 rows in set (0.001 sec)


MariaDB [(none)]> create database db_mhs;

Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| db_mhs |

| information_schema |

| mysql |

| performance_schema |

| phpmyadmin |

| test |

+--------------------+

6 rows in set (0.001 sec)

MariaDB [(none)]> drop database db_mhs;

Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| phpmyadmin |

| test |

+--------------------+
5 rows in set (0.001 sec)

MariaDB [(none)]> create database db_mhs;

Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> use db_mhs;

Database changed

MariaDB [db_mhs]> create table mhs(no int(4));

Query OK, 0 rows affected (0.026 sec)

MariaDB [db_mhs]> desc mhs;

+-------+--------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+--------+------+-----+---------+-------+

| no | int(4) | YES | | NULL | |

+-------+--------+------+-----+---------+-------+

1 row in set (0.015 sec)

MariaDB [db_mhs]> alter table mhs add nama varchar(50);

Query OK, 0 rows affected (0.018 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [db_mhs]> desc mhs;

+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| no | int(4) | YES | | NULL | |

| nama | varchar(50) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+
2 rows in set (0.014 sec)

MariaDB [db_mhs]> alter table mhs add npm char(13);

Query OK, 0 rows affected (0.017 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [db_mhs]> desc mhs;

+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| no | int(4) | YES | | NULL | |

| nama | varchar(50) | YES | | NULL | |

| npm | char(13) | YES | | NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.014 sec)

MariaDB [db_mhs]> alter table mhs add kelas varchar(1);

Query OK, 0 rows affected (0.017 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [db_mhs]> alter table mhs add prodi varchar(25);

Query OK, 0 rows affected (0.007 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [db_mhs]> alter table mhs add fakultas varchar(25);

Query OK, 0 rows affected (0.016 sec)

Records: 0 Duplicates: 0 Warnings: 0

MariaDB [db_mhs]> desc mhs;


+----------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+

| no | int(4) | YES | | NULL | |

| nama | varchar(50) | YES | | NULL | |

| npm | char(13) | YES | | NULL | |

| kelas | varchar(1) | YES | | NULL | |

| prodi | varchar(25) | YES | | NULL | |

| fakultas | varchar(25) | YES | | NULL | |

+----------+-------------+------+-----+---------+-------+

6 rows in set (0.014 sec)

MariaDB [db_mhs]> insert into mhs values('1','teguh pambudi','2110631230021','a','pendidikan


mtk','fkip');

Query OK, 1 row affected (0.004 sec)

MariaDB [db_mhs]> select*from mhs;

+------+---------------+---------------+-------+----------------+----------+

| no | nama | npm | kelas | prodi | fakultas |

+------+---------------+---------------+-------+----------------+----------+

| 1 | teguh pambudi | 2110631230021 | a | pendidikan mtk | fkip |

+------+---------------+---------------+-------+----------------+----------+

1 row in set (0.001 sec)

MariaDB [db_mhs]> insert into mhs values('2','teguh prasetyo','2110631230022','a','pendidikan


ipa','fkip');

Query OK, 1 row affected (0.003 sec)

MariaDB [db_mhs]> insert into mhs values('3','teguh raharjo','2110631230023','b','teknik


kimia','teknik');
Query OK, 1 row affected (0.013 sec)

MariaDB [db_mhs]> insert into mhs values('4','teguh


santoso','2110631230024','c','kedokteran','kesehatan');

Query OK, 1 row affected (0.003 sec)

MariaDB [db_mhs]> insert into mhs values('5',teguh pendirian','2110631230021','d','ilmu politik','fisip');

'> insert into mhs values('5',teguh pendirian','2110631230021','d','ilmu politik','fisip');

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near 'pendirian','2110631230021','d','ilmu
politik','fisip');

insert into mhs value...' at line 1

MariaDB [db_mhs]> insert into mhs values('5','teguh pambudi','2110631230025','d','pendidikan


agama','fai');

Query OK, 1 row affected (0.013 sec)

MariaDB [db_mhs]> select*from mhs;

+------+----------------+---------------+-------+------------------+-----------+

| no | nama | npm | kelas | prodi | fakultas |

+------+----------------+---------------+-------+------------------+-----------+

| 1 | teguh pambudi | 2110631230021 | a | pendidikan mtk | fkip |

| 2 | teguh prasetyo | 2110631230022 | a | pendidikan ipa | fkip |

| 3 | teguh raharjo | 2110631230023 | b | teknik kimia | teknik |

| 4 | teguh santoso | 2110631230024 | c | kedokteran | kesehatan |

| 5 | teguh pambudi | 2110631230025 | d | pendidikan agama | fai |

+------+----------------+---------------+-------+------------------+-----------+

5 rows in set (0.001 sec)

MariaDB [db_mhs]> delete from mhs where no=1;

Query OK, 1 row affected (0.013 sec)


MariaDB [db_mhs]> select*from mhs;

+------+----------------+---------------+-------+------------------+-----------+

| no | nama | npm | kelas | prodi | fakultas |

+------+----------------+---------------+-------+------------------+-----------+

| 2 | teguh prasetyo | 2110631230022 | a | pendidikan ipa | fkip |

| 3 | teguh raharjo | 2110631230023 | b | teknik kimia | teknik |

| 4 | teguh santoso | 2110631230024 | c | kedokteran | kesehatan |

| 5 | teguh pambudi | 2110631230025 | d | pendidikan agama | fai |

+------+----------------+---------------+-------+------------------+-----------+

4 rows in set (0.000 sec)

MariaDB [db_mhs]>

You might also like