sedang mencari ilmu

my sql praktik di kampus

contoh program MySQL
mysql> create database coba;
Query OK, 1 row affected (0.02 sec)
mysql> create table siswa(nim char(8) primary key not null,nama char(10),tgl_lahir date,alamat varchar(20),no_telp char(15));
ERROR 1046 (3D000): No database selected
mysql> use coba;
Database changed
mysql> create table siswa(nim char(8) primary key not null,nama char(10),tgl_lahir date,alamat varchar(20),no_telp char(15));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into siswa values(“07018206″,”budi”,”1990-06-06″,”glagah”,”12345678″),(“09018202″,”hasni”,”1991-03-09″,”bantul”,”0878652″);
Query OK, 2 rows affected (0.05 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from siswa;
+———-+——-+————+——–+———-+
| nim | nama | tgl_lahir | alamat | no_telp |
+———-+——-+————+——–+———-+
| 07018206 | budi | 1990-06-06 | glagah | 12345678 |
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
+———-+——-+————+——–+———-+
2 rows in set (0.00 sec)
mysql> update siswa nama=”sasa” where nim=”07018206″;
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 ‘=”sasa” where nim=”07018206″‘ at line 1
mysql> select * from siswa;
+———-+——-+————+——–+———-+
| nim | nama | tgl_lahir | alamat | no_telp |
+———-+——-+————+——–+———-+
| 07018206 | budi | 1990-06-06 | glagah | 12345678 |
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
+———-+——-+————+——–+———-+
2 rows in set (0.00 sec)
mysql> update siswa set nama=”sasa” where nim=”07018206″;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from siswa;
+———-+——-+————+——–+———-+
| nim | nama | tgl_lahir | alamat | no_telp |
+———-+——-+————+——–+———-+
| 07018206 | sasa | 1990-06-06 | glagah | 12345678 |
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
+———-+——-+————+——–+———-+
2 rows in set (0.00 sec)
mysql> select nim, nama from siswa;
+———-+——-+
| nim | nama |
+———-+——-+
| 07018206 | sasa |
| 09018202 | hasni |
+———-+——-+
2 rows in set (0.00 sec)
mysql> update siswa
-> set nama=”irfan”
-> where nim=”07018206″;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update siswa
-> set tgl_lahir=”1990-06-05″
-> where nim=”09018206″;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> select * from siswa;
+———-+——-+————+——–+———-+
| nim | nama | tgl_lahir | alamat | no_telp |
+———-+——-+————+——–+———-+
| 07018206 | irfan | 1990-06-06 | glagah | 12345678 |
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
+———-+——-+————+——–+———-+
2 rows in set (0.00 sec)
mysql> update siswa set tgl_lahir=”1990-06-05″ where nama=”irfan”;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from siswa;
+———-+——-+————+——–+———-+
| nim | nama | tgl_lahir | alamat | no_telp |
+———-+——-+————+——–+———-+
| 07018206 | irfan | 1990-06-05 | glagah | 12345678 |
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
+———-+——-+————+——–+———-+
2 rows in set (0.00 sec)
mysql> delete from siswa where alamat=”glagah”;
Query OK, 1 row affected (0.02 sec)
mysql> select * from siswa;
+———-+——-+————+——–+———+
| nim | nama | tgl_lahir | alamat | no_telp |
+———-+——-+————+——–+———+
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
+———-+——-+————+——–+———+
1 row in set (0.00 sec)
mysql> insert into siswa values(“07018206″,”budi”,”1990-06-06″,”glagah”,”12345678″),(“09018200″,”itul”,”1991-04-13″,”bantul”,”08564321″);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from siswa;
+———-+——-+————+——–+———-+
| nim | nama | tgl_lahir | alamat | no_telp |
+———-+——-+————+——–+———-+
| 07018206 | budi | 1990-06-06 | glagah | 12345678 |
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
| 09018200 | itul | 1991-04-13 | bantul | 08564321 |
+———-+——-+————+——–+———-+
3 rows in set (0.00 sec)
mysql> alter table siswa change alamat alamat_rumah varchar(20)
-> ;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select * from siswa;
+———-+——-+————+————–+———-+
| nim | nama | tgl_lahir | alamat_rumah | no_telp |
+———-+——-+————+————–+———-+
| 07018206 | budi | 1990-06-06 | glagah | 12345678 |
| 09018202 | hasni | 1991-03-09 | bantul | 0878652 |
| 09018200 | itul | 1991-04-13 | bantul | 08564321 |
+———-+——-+————+————–+———-+
3 rows in set (0.00 sec)
mysql> alter table siswa drop no_telp;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from siswa;
+———-+——-+————+————–+
| nim | nama | tgl_lahir | alamat_rumah |
+———-+——-+————+————–+
| 07018206 | budi | 1990-06-06 | glagah |
| 09018202 | hasni | 1991-03-09 | bantul |
| 09018200 | itul | 1991-04-13 | bantul |
+———-+——-+————+————–+
3 rows in set (0.00 sec)
mysql> alter table siswa rename siswa-siswi;
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 ‘-siswi’ at line 1
mysql> alter table siswa rename siswa_siswi;
Query OK, 0 rows affected (0.01 sec)
mysql> select * from siswa_siswi;
+———-+——-+————+————–+
| nim | nama | tgl_lahir | alamat_rumah |
+———-+——-+————+————–+
| 07018206 | budi | 1990-06-06 | glagah |
| 09018202 | hasni | 1991-03-09 | bantul |
| 09018200 | itul | 1991-04-13 | bantul |
+———-+——-+————+————–+
3 rows in set (0.00 sec)
mysql> select nim. nama from siswa_siswi desc;
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 ‘desc’ at line 1
mysql> select nim. nama from siswa_siswi descending;
ERROR 1054 (42S22): Unknown column ‘nim.nama’ in ‘field list’
mysql> select nim, nama from siswa_siswi order by desc;
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 ‘desc’ at line 1
mysql> select nim, nama from siswa_siswi order by nama desc;
+———-+——-+
| nim | nama |
+———-+——-+
| 09018200 | itul |
| 09018202 | hasni |
| 07018206 | budi |
+———-+——-+
3 rows in set (0.01 sec)
mysql> select nim, nama from siswa_siswi order by nama asc;
+———-+——-+
| nim | nama |
+———-+——-+
| 07018206 | budi |
| 09018202 | hasni |
| 09018200 | itul |
+———-+——-+
3 rows in set (0.00 sec)
mysql> alter table siswa_siswi add umur int;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from siswa_siswi;
+———-+——-+————+————–+——+
| nim | nama | tgl_lahir | alamat_rumah | umur |
+———-+——-+————+————–+——+
| 07018206 | budi | 1990-06-06 | glagah | NULL |
| 09018202 | hasni | 1991-03-09 | bantul | NULL |
| 09018200 | itul | 1991-04-13 | bantul | NULL |
+———-+——-+————+————–+——+
3 rows in set (0.00 sec)
mysql> update siswa
-> set umur=”21″
-> where nim=”07018206″;
ERROR 1146 (42S02): Table ‘coba.siswa’ doesn’t exist
mysql> update siswa_siswi set umur=”21″ where nim=”07018206″;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update siswa_siswi set umur=”20″ where nim=”09018202″;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update siswa_siswi set umur=”20″ where nim=”09018200″;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from siswa_siswi;
+———-+——-+————+————–+——+
| nim | nama | tgl_lahir | alamat_rumah | umur |
+———-+——-+————+————–+——+
| 07018206 | budi | 1990-06-06 | glagah | 21 |
| 09018202 | hasni | 1991-03-09 | bantul | 20 |
| 09018200 | itul | 1991-04-13 | bantul | 20 |
+———-+——-+————+————–+——+
3 rows in set (0.00 sec)
mysql> select sum(umur) from siswa_siswi;
+———–+
| sum(umur) |
+———–+
| 61 |
+———–+
1 row in set (0.01 sec)
mysql> select avg(umur) from siswa_siswi;
+———–+
| avg(umur) |
+———–+
| 20.3333 |
+———–+
1 row in set (0.01 sec)
mysql> select distinct(umur) from siswa_siswi;
+——+
| umur |
+——+
| 21 |
| 20 |
+——+
2 rows in set (0.01 sec)
mysql> select top(umur) from siswa_siswi;
ERROR 1305 (42000): FUNCTION coba.top does not exist
mysql> select sum(umur) as jumlah from siswa_siswi;
+——–+
| jumlah |
+——–+
| 61 |
+——–+
1 row in set (0.00 sec)
mysql> ^CCtrl-C — exit!
Aborted
root@debian:/home/praktikan# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 79
Server version: 5.1.49-3 (Debian)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use coba;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> desc coba;
ERROR 1146 (42S02): Table ‘coba.coba’ doesn’t exist
mysql>

cara menghapus virus di flash dish

Caranya:

1.Pilih Accessories pada Program all
2.Pilih Command Prompt
3.Kemudian ketik perintah dibawah ini:
RD / S / Q \\.\G:\AUTORUN.INF
4.Kemudian Enter

Selesai