Tutorial cara buat database mysql
sebenernya tulisan ini cuma untuk mengingatkan saya supaya tidak lupa ketika membuatnya lagi, karena ilmu komputer itu sangantlah bejibun hehehehe ..
okey langsung saja yeaaah ..
pertama buka terminal ( ctrl + alt + T )
Ketikkan
sebenernya tulisan ini cuma untuk mengingatkan saya supaya tidak lupa ketika membuatnya lagi, karena ilmu komputer itu sangantlah bejibun hehehehe ..
okey langsung saja yeaaah ..
pertama buka terminal ( ctrl + alt + T )
Ketikkan
/etc/init.d/mysql start */ <=== untuk menghidupkan dulu mysql y atau buka applications /Backtrack /services /mysqld /msqlstart
setelah itu ketikkan kembali di terminal
root@bt:~# mysql -u root -p
Enter password:toor
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 42 Server version: 5.1.63-0ubuntu0.10.04.1 (Ubuntu) Copyright (c) 2000, 2011, 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> create database stmik_mic; Query OK, 1 row affected (0.00 sec) mysql> use stmik_mic; Database changed
mysql> create table mahasiswa( -> nim varchar(15), -> nama text, -> jurusan text, -> primary key(nim)); Query OK, 0 rows affected (0.11 sec) mysql> show tables; +---------------------+ | Tables_in_stmik_mic | +---------------------+ | mahasiswa | +---------------------+ 1 row in set (0.00 sec) mysql> desc mahasiswa; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | nim | varchar(15) | NO | PRI | | | | nama | text | YES | | NULL | | | jurusan | text | YES | | NULL | | +---------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> alter table mahasiswa add thn_angkatan varchar(4); Query OK, 0 rows affected (0.10 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc mahasiswa; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | nim | varchar(15) | NO | PRI | | | | nama | text | YES | | NULL | | | jurusan | text | YES | | NULL | | | thn_angkatan | varchar(4) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> alter table mahasiswa add semester text; Query OK, 0 rows affected (0.14 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc mahasiswa; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | nim | varchar(15) | NO | PRI | | | | nama | text | YES | | NULL | | | jurusan | text | YES | | NULL | | | thn_angkatan | varchar(4) | YES | | NULL | | | semester | text | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 5 rows in set (0.01 sec)
mysql> alter table mahasiswa modify semester varchar(10); Query OK, 0 rows affected (0.13 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc mahasiswa; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | nim | varchar(15) | NO | PRI | | | | nama | text | YES | | NULL | | | jurusan | text | YES | | NULL | | | thn_angkatan | varchar(4) | YES | | NULL | | | semester | varchar(10) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 5 rows in set (0.01 sec) mysql> alter table mahasiswa modify semester varchar(10) not null; Query OK, 0 rows affected (0.11 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc mahasiswa; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | nim | varchar(15) | NO | PRI | | | | nama | text | YES | | NULL | | | jurusan | text | YES | | NULL | | | thn_angkatan | varchar(4) | YES | | NULL | | | semester | varchar(10) | NO | | NULL | | +--------------+-------------+------+-----+---------+-------+ 5 rows in set (0.00 sec) mysql> alter table mahasiswa drop semester; Query OK, 0 rows affected (0.12 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc mahasiswa; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | nim | varchar(15) | NO | PRI | | | | nama | text | YES | | NULL | | | jurusan | text | YES | | NULL | | | thn_angkatan | varchar(4) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> insert into mahasiswa values( -> '11164061','bayu','teknik informatika','2012'); Query OK, 1 row affected (0.00 sec) mysql> select *from mahasiswa; +----------+------+--------------------+--------------+ | nim | nama | jurusan | thn_angkatan | +----------+------+--------------------+--------------+ | 11164061 | bayu | teknik informatika | 2012 | +----------+------+--------------------+--------------+ 1 row in set (0.00 sec) mysql> update mahasiswa set nama='bayu saputra' where nim=11164061; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select *from mahasiswa; +----------+--------------+--------------------+--------------+ | nim | nama | jurusan | thn_angkatan | +----------+--------------+--------------------+--------------+ | 11164061 | bayu saputra | teknik informatika | 2012 | +----------+--------------+--------------------+--------------+ 1 row in set (0.00 sec) mysql> insert into mahasiswa values -> ('11164062','aden','sistem informatika','2012'); Query OK, 1 row affected (0.00 sec) mysql> select *from mahasiswa;
+----------+--------------+--------------------+--------------+ | nim | nama | jurusan | thn_angkatan | +----------+--------------+--------------------+--------------+ | 11164061 | bayu saputra | teknik informatika | 2012 | | 11164062 | aden | sistem informatika | 2012 | +----------+--------------+--------------------+--------------+ 2 rows in set (0.00 sec) mysql> delete from mahasiswa where nim=11164062; Query OK, 1 row affected (0.00 sec) mysql> select *from mahasiswa; +----------+--------------+--------------------+--------------+ | nim | nama | jurusan | thn_angkatan | +----------+--------------+--------------------+--------------+ | 11164061 | bayu saputra | teknik informatika | 2012 | +----------+--------------+--------------------+--------------+ 1 row in set (0.00 sec)
mysql> quit Bye root@bt:~#
itulah cara pembuatan database di backtrack, sekian terimakasih.
Comments
Post a Comment