Cara mysql melalui cmd
Klik START - RUN - ketik CMD - OK
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\RPL Department>cd\
C:\>cd xampp\mysql\bin\
C:\xampp\mysql\bin>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 93
Server version: 5.1.41 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> show databases;
+----------------------------+
| Database |
+----------------------------+
| information_schema |\
| penjualan |
| phonebook |
| phpmyadmin |
| sekolah |
| senayan |
| sisfokol |
| smkn1stn_situssmkn1 |
| webelec |
| webmail |
| webtemp |
+----------------------------+
30 rows in set (0.00 sec)
.:| Jika database yang dimaksud belum ada,
buatlah database seperti di bawah ini :
===================================
mysql>create database pegawai;
Query OK, 1 row affected (0.00 sec)
.:| Jika database yang dimaksud sudah ada,
gunakan perintah seperti di bawah ini :
===================================
mysql>use pegawai;
Database changed
mysql> show tables;
+-------------------+
| Tables_in_pegawai |
+-------------------+
| pribadi |
+-------------------+
1 row in set (0.05 sec)
.:| Perintah untuk melihat struktur tabel
==================================
mysql>describe pribadi; ATAU desc pribadi;
.:| Perintah untuk membuat tabel baru
==================================
mysql> create table pribadi (Nip INT(5) NOT NULL PRIMARY KEY,
->Nama VARCHAR (35) NOT NULL,
->Tgl_lahir DATE,
->Sex ENUM('P','W'),
->Alamat VARCHAR(35),
->Kota VARCHAR(15));
Query OK, 0 rows affected (0.03 sec)
mysql> show tables;
+-------------------+
| Tables_in_pegawai |
+-------------------+
| pribadi |
+-------------------+
1 row in set (0.05 sec)
mysql> describe pribadi;
+--------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| Nip | int(5) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| Sex | enum('P','W') | YES | | NULL | |
| Status_Kawin | varchar(10) | YES | | NULL | |
| Alamat | varchar(35) | YES | | NULL | |
| Kota | varchar(15) | YES | | NULL | |
+--------------+---------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
KEY ada 2 : ==> mengidentifikasi tabel
===============================
1) PRIMARY KEY (Kunci Utama)
2) FOREIGN KEY (Kunci Tambahan)
ALTER TABLE : ==> untuk merubah struktur tabel
========================================
1) ADD --> menambah kolom atau field baru == AFTER
2) CHANGE --> merubah nama kolom atau field
3) RENAME TO --> merubah nama tabel
4) DROP --> menghapus kolom atau field
mysql> ALTER TABLE pribadi CHANGE Alamat Tempat_Tinggal TEXT(20);
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe pribadi;
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| Nip | int(5) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| Sex | enum('P','W') | YES | | NULL | |
| Tempat_Tinggal | tinytext | YES | | NULL | |
| Kota | varchar(15) | YES | | NULL | |
+----------------+---------------+------+-----+---------+-------+
7 rows in set (0.02 sec)
mysql> show tables;
+-------------------+
| Tables_in_pegawai |
+-------------------+
| pribadi |
+-------------------+
1 row in set (0.00 sec)
mysql> ALTER TABLE pribadi RENAME TO data_pribadi;
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+-------------------+
| Tables_in_pegawai |
+-------------------+
| data_pribadi |
+-------------------+
1 row in set (0.00 sec)
mysql> ALTER TABLE data_pribadi ADD Status_Kawin VARCHAR(10) AFTER Sex;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe pribadi;
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| Nip | int(5) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| Sex | enum('P','W') | YES | | NULL | |
| Status_Kawin | varchar(10) | YES | | NULL | |
| Tempat_Tinggal | tinytext | YES | | NULL | |
| Kota | varchar(15) | YES | | NULL | |
+----------------+---------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
mysql> ALTER TABLE data_pribadi DROP Status_Kawin;
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc pribadi; atau describe pribadi;
+----------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------+-------+
| Nip | int(5) | NO | PRI | NULL | |
| Nama | varchar(35) | NO | | NULL | |
| Tgl_lahir | date | YES | | NULL | |
| Sex | enum('P','W') | YES | | NULL | |
| Tempat_Tinggal | tinytext | YES | | NULL | |
| Kota | varchar(15) | YES | | NULL | |
+----------------+---------------+------+-----+---------+-------+
6 rows in set (0.02 sec)
1) INSERT INTO nama_tabel SET nilai/data/record
---------------------------------------------------------------------
mysql> INSERT INTO pribadi SET Nip='12345', Nama='Riska', Tgl_Lahir='1987/05/20', Sex='P', Tempat_Tinggal='Karing-karing', Kota='Bau-Bau';
Query OK, 1 row affected (0.00 sec)
2) INSERT INTO nama_tabel (nama_kolom) VALUES (nilai/data/record)
-------------------------------------------------------------------------------------------------
mysql> INSERT INTO pribadi(Nip, Nama, Tgl_lahir, Sex, Tempat_Tinggal, Kota) VALUES ('23456','M. Roni Sianturi','1965/12/23', 'L', 'Jl. Sijawangkati 1', 'Bau-Bau');
3) INSERT INTO nama_tabel VALUES nilai/data/record -----> Direct INPUT
-----------------------------------------------------------------------------------------------------
mysql> INSERT INTO pribadi VALUES ('34532', 'M. Fendi Kurniawan','1987/05/20','P', 'Jl. Murhum 54', 'Bau-Bau');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM pribadi;
+-------+------------------+------------+------+--------------------+---------+
| Nip | Nama | Tgl_lahir | Sex | Tempat_Tinggal | Kota |
+-------+------------------+------------+------+--------------------+---------+
| 12345 | Riska | 1987-05-20 | P | Karing-karing | Bau-Bau |
| 23456 | M. Roni Sianturi | 1965-12-23 | P | Jl. Sijawangkati 1 | Bau-Bau |
+-------+------------------+------------+------+--------------------+---------+
2 rows in set (0.00 sec)
mysql> SELECT Nip,Nama,Tgl_lahir,Sex,Tempat_Tinggal,Kota FROM pribadi;
+-------+--------------------+------------+------+--------------------+---------
+
| Nip | Nama | Tgl_lahir | Sex | Tempat_Tinggal | Kota
|
+-------+--------------------+------------+------+--------------------+---------
+
| 12345 | Riska | 1987-05-20 | P | Karing-karing | Bau-Bau
|
| 23456 | M. Roni Sianturi | 1965-12-23 | P | Jl. Sijawangkati 1 | Bau-Bau
|
| 34532 | M. Fendi Kurniawan | 1987-05-20 | P | Jl. Murhum 54 | Bau-Bau
|
+-------+--------------------+------------+------+--------------------+---------
+
3 rows in set (0.00 sec)
mysql> SELECT Nip, Nama FROM pribadi;
+-------+--------------------+
| Nip | Nama |
+-------+--------------------+
| 12345 | Riska |
| 23456 | M. Roni Sianturi |
| 34532 | M. Fendi Kurniawan |
+-------+--------------------+
3 rows in set (0.00 sec)
mysql> SELECT Nama, Tgl_lahir FROM pribadi;
+--------------------+------------+
| Nama | Tgl_lahir |
+--------------------+------------+
| Riska | 1987-05-20 |
| M. Roni Sianturi | 1965-12-23 |
| M. Fendi Kurniawan | 1987-05-20 |
+--------------------+------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM pribadi WHERE Nama = 'Riska';
+-------+-------+------------+------+----------------+---------+
| Nip | Nama | Tgl_lahir | Sex | Tempat_Tinggal | Kota |
+-------+-------+------------+------+----------------+---------+
| 12345 | Riska | 1987-05-20 | P | Karing-karing | Bau-Bau |
+-------+-------+------------+------+----------------+---------+
1 row in set (0.00 sec)
C:\xampp\mysql\data\pribadi
\cdcol
\mysql
\test
\webtemp
\pegawai
mysql> select * from mdl_block where name like 's%';
+----+-------------------+------------+------+----------+---------+----------+
| id | name | version | cron | lastcron | visible | multiple |
+----+-------------------+------------+------+----------+---------+----------+
| 24 | search | 2008031500 | 1 | 0 | 1 | 0 |
| 25 | search_forums | 2007101509 | 0 | 0 | 1 | 0 |
| 26 | section_links | 2007101511 | 0 | 0 | 1 | 0 |
| 27 | site_main_menu | 2007101509 | 0 | 0 | 1 | 0 |
| 28 | social_activities | 2007101509 | 0 | 0 | 1 | 0 |
+----+-------------------+------------+------+----------+---------+----------+
5 rows in set (0.00 sec)
mysql> select * from mdl_block where name like 'a%';
+----+------------------+------------+------+----------+---------+----------+
| id | name | version | cron | lastcron | visible | multiple |
+----+------------------+------------+------+----------+---------+----------+
| 1 | activity_modules | 2007101509 | 0 | 0 | 1 | 0 |
| 2 | admin | 2007101509 | 0 | 0 | 1 | 0 |
| 3 | admin_bookmarks | 2007101509 | 0 | 0 | 1 | 0 |
| 4 | admin_tree | 2007101509 | 0 | 0 | 1 | 0 |
+----+------------------+------------+------+----------+---------+----------+
4 rows in set (0.00 sec)
mysql> select * from mdl_block where multiple='1';
+----+-----------------+------------+------+----------+---------+----------+
| id | name | version | cron | lastcron | visible | multiple |
+----+-----------------+------------+------+----------+---------+----------+
| 10 | glossary_random | 2005040500 | 0 | 0 | 1 | 1 |
| 11 | html | 2004123000 | 0 | 0 | 1 | 1 |
| 14 | mentees | 2007030900 | 0 | 0 | 1 | 1 |
| 20 | quiz_results | 2005082300 | 0 | 0 | 1 | 1 |
| 22 | rss_client | 2006100102 | 0 | 0 | 1 | 1 |
+----+-----------------+------------+------+----------+---------+----------+
5 rows in set (0.00 sec)
0 komentar:
Posting Komentar