The document shows the steps taken to create and populate a MySQL database called pbd. The following tables were created: siswa, guru, mahasiswa, matakuliah, and krs. Data was inserted into the siswa and guru tables. Columns in the tables were updated, rows were deleted, and selections were made to view the data.
1. [root@koneksi ~]# service mysqld start
Starting mysqld: [ OK ]
[root@koneksi ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.1.67 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| appPegawai |
| coba |
| dbpegawai |
| mysql |
| test |
+--------------------+
6 rows in set (0.04 sec)
mysql> create database pbd;
Query OK, 1 row affected (0.00 sec)
mysql> use pbd;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table siswa(
-> id int primary key,
-> nama varchar(30),
-> alamat text,
-> jk char(1));
Query OK, 0 rows affected (0.08 sec)
mysql> show tables;
+---------------+
| Tables_in_pbd |
+---------------+
| siswa |
+---------------+
1 row in set (0.00 sec)
mysql> desc siswa;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| nama | varchar(30) | YES | | NULL | |
| alamat | text | YES | | NULL | |
| jk | char(1) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
mysql> insert into siswa(id, nama, alamat, jk)
2. -> values(1, 'Sapari Andi', 'Mampang', 'L');
Query OK, 1 row affected (0.00 sec)
mysql> insert into siswa(id, nama, alamat, jk)values(1, 'Sapari Andi',
'Mampang', 'L')
-> ;
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> insert into siswa(id, nama, alamat, jk)
-> values (2, 'Dede Hidayat');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into siswa(id, nama) values (2, 'Dede Hidayat');
Query OK, 1 row affected (0.00 sec)
mysql> show tables;
+---------------+
| Tables_in_pbd |
+---------------+
| siswa |
+---------------+
1 row in set (0.00 sec)
mysql> desc siswa;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| nama | varchar(30) | YES | | NULL | |
| alamat | text | YES | | NULL | |
| jk | char(1) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select * from siswa;
+----+--------------+---------+------+
| id | nama | alamat | jk |
+----+--------------+---------+------+
| 1 | Sapari Andi | Mampang | L |
| 2 | Dede Hidayat | NULL | NULL |
+----+--------------+---------+------+
2 rows in set (0.00 sec)
mysql> insert into siswa values(3, 'Heni Lestari', 'Kalibata', 'P');
Query OK, 1 row affected (0.00 sec)
mysql> select nama from siswa;
+--------------+
| nama |
+--------------+
| Sapari Andi |
| Dede Hidayat |
| Heni Lestari |
+--------------+
3 rows in set (0.00 sec)
mysql> select * from siswa;
+----+--------------+----------+------+
| id | nama | alamat | jk |
+----+--------------+----------+------+
| 1 | Sapari Andi | Mampang | L |
| 2 | Dede Hidayat | NULL | NULL |
| 3 | Heni Lestari | Kalibata | P |
+----+--------------+----------+------+
3 rows in set (0.00 sec)
3. mysql> update siswa set alamat='Ciamis' where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from siswa;
+----+--------------+----------+------+
| id | nama | alamat | jk |
+----+--------------+----------+------+
| 1 | Sapari Andi | Mampang | L |
| 2 | Dede Hidayat | Ciamis | NULL |
| 3 | Heni Lestari | Kalibata | P |
+----+--------------+----------+------+
3 rows in set (0.00 sec)
mysql> update siswa set jk='L' where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from siswa;
+----+--------------+----------+------+
| id | nama | alamat | jk |
+----+--------------+----------+------+
| 1 | Sapari Andi | Mampang | L |
| 2 | Dede Hidayat | Ciamis | L |
| 3 | Heni Lestari | Kalibata | P |
+----+--------------+----------+------+
3 rows in set (0.00 sec)
mysql> update siswa set jk=1 where jk='P';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from siswa;
+----+--------------+----------+------+
| id | nama | alamat | jk |
+----+--------------+----------+------+
| 1 | Sapari Andi | Mampang | L |
| 2 | Dede Hidayat | Ciamis | L |
| 3 | Heni Lestari | Kalibata | 1 |
+----+--------------+----------+------+
3 rows in set (0.00 sec)
mysql> update siswa set jk=0 where jk='L';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select * from siswa;
+----+--------------+----------+------+
| id | nama | alamat | jk |
+----+--------------+----------+------+
| 1 | Sapari Andi | Mampang | 0 |
| 2 | Dede Hidayat | Ciamis | 0 |
| 3 | Heni Lestari | Kalibata | 1 |
+----+--------------+----------+------+
3 rows in set (0.00 sec)
mysql> delete from siswa where id=2;
Query OK, 1 row affected (0.00 sec)
mysql> select * from siswa;
+----+--------------+----------+------+
| id | nama | alamat | jk |
+----+--------------+----------+------+
| 1 | Sapari Andi | Mampang | 0 |
4. | 3 | Heni Lestari | Kalibata | 1 |
+----+--------------+----------+------+
2 rows in set (0.00 sec)
mysql> select * from siswa order by alamat;
+----+--------------+----------+------+
| id | nama | alamat | jk |
+----+--------------+----------+------+
| 3 | Heni Lestari | Kalibata | 1 |
| 1 | Sapari Andi | Mampang | 0 |
+----+--------------+----------+------+
2 rows in set (0.00 sec)
mysql> create table guru(
-> id int primary key auto_increment,
-> nama varchar(30),
-> alamat text,
-> gaji double);
Query OK, 0 rows affected (0.06 sec)
mysql> insert into guru(nama,alamat,gaji)
-> values('Karim Santoso','Pancoran',8000000);
Query OK, 1 row affected (0.00 sec)
mysql> select * from guru;
+----+---------------+----------+---------+
| id | nama | alamat | gaji |
+----+---------------+----------+---------+
| 1 | Karim Santoso | Pancoran | 8000000 |
+----+---------------+----------+---------+
1 row in set (0.00 sec)
mysql> desc guru;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nama | varchar(30) | YES | | NULL | |
| alamat | text | YES | | NULL | |
| gaji | double | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> create table mahasiswa(
-> npm int primary key auto_increment,
-> nama varchar(30),
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 3
mysql> show tables;
+---------------+
| Tables_in_pbd |
+---------------+
| guru |
| siswa |
+---------------+
2 rows in set (0.00 sec)
mysql> create table mahasiswa(
-> npm int primary key auto_increment,
-> nama varchar(30));
Query OK, 0 rows affected (0.06 sec)
5. mysql> create table matakuliah(
-> kodemk int primary key,
-> mk varchar(30));
Query OK, 0 rows affected (0.06 sec)
mysql> create table krs(
-> npm int,
-> ta int,
-> semester char(1),
-> kodemk int);
Query OK, 0 rows affected (0.07 sec)
mysql> show tables;
+---------------+
| Tables_in_pbd |
+---------------+
| guru |
| krs |
| mahasiswa |
| matakuliah |
| siswa |
+---------------+
5 rows in set (0.00 sec)
mysql> desc pbd;
ERROR 1146 (42S02): Table 'pbd.pbd' doesn't exist
mysql> show tables;
+---------------+
| Tables_in_pbd |
+---------------+
| guru |
| krs |
| mahasiswa |
| matakuliah |
| siswa |
+---------------+
5 rows in set (0.00 sec)
mysql> desc krs;
+----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| npm | int(11) | YES | | NULL | |
| ta | int(11) | YES | | NULL | |
| semester | char(1) | YES | | NULL | |
| kodemk | int(11) | YES | | NULL | |
+----------+---------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> desc mahasiswa;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| npm | int(11) | NO | PRI | NULL | auto_increment |
| nama | varchar(30) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> desc matakuliah;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| kodemk | int(11) | NO | PRI | NULL | |
| mk | varchar(30) | YES | | NULL | |