Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20
Microsoft Windows [Version 10.0.19045.
2251] (c) Microsoft Corporation. All rights reserved.
C:\Users\WINDOWS 10>mysql -u root -p
Enter password: *********** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 44 Server version: 5.7.40-log MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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 engines;
+--------------------+---------+----------------------------------------------------------------+-------------- +------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+-------------- +------+------------+ | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | +--------------------+---------+----------------------------------------------------------------+-------------- +------+------------+ 9 rows in set (0.01 sec)
+--------------------+ | Database | +--------------------+ | information_schema | | belajar_mysql | | classicmodels | | mysql | | performance_schema | | sakila | | shop_app | | sys | | world | +--------------------+ 9 rows in set (0.00 sec)
mysql> use belajar_mysql;
Database changed mysql> create table barang ( -> id INT, -> nama VARCHAR(100), -> harga INT, -> jumlah INT -> )engine = InnoDB; Query OK, 0 rows affected (0.07 sec) mysql> show tables; +-------------------------+ | Tables_in_belajar_mysql | +-------------------------+ | barang | +-------------------------+ 1 row in set (0.00 sec)
mysql> describe barang;
+--------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | nama | varchar(100) | YES | | NULL | | | harga | int(11) | YES | | NULL | | | jumlah | int(11) | YES | | NULL | | +--------+--------------+------+-----+---------+-------+ 4 rows in set (0.02 sec)
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | harga | int(11) | YES | | NULL | | | jumlah | int(11) | YES | | NULL | | | deskripsi | text | YES | | NULL | | | nama | varchar(200) | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
mysql> alter table barang
-> modify nama varchar(200) firts; 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 'firts' at line 2 mysql> alter table barang -> modify nama varchar(200)first; Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | nama | varchar(200) | YES | | NULL | | | id | int(11) | YES | | NULL | | | harga | int(11) | YES | | NULL | | | jumlah | int(11) | YES | | NULL | | | deskripsi | text | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
mysql> alter table barang
-> modify id int not null; Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | nama | varchar(200) | YES | | NULL | | | id | int(11) | NO | | NULL | | | harga | int(11) | YES | | NULL | | | jumlah | int(11) | YES | | NULL | | | deskripsi | text | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | nama | varchar(200) | NO | | NULL | | | id | int(11) | NO | | NULL | | | harga | int(11) | YES | | NULL | | | jumlah | int(11) | YES | | NULL | | | deskripsi | text | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
mysql> show create table barang;
+-------- +------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------+ | Table | Create Table | +-------- +------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------+ | barang | CREATE TABLE `barang` ( `nama` varchar(200) NOT NULL, `id` int(11) NOT NULL, `harga` int(11) DEFAULT NULL, `jumlah` int(11) DEFAULT NULL, `deskripsi` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +-------- +------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> desc barang;
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | nama | varchar(200) | NO | | NULL | | | id | int(11) | NO | | NULL | | | harga | int(11) | YES | | NULL | | | jumlah | int(11) | YES | | NULL | | | deskripsi | text | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
mysql> alter table barang
-> modify harga,jumlah int not null default 0; 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 'jumlah int not null default 0' at line 2 mysql> alter table barang -> modify harga int not null default 0; Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table barang
-> modify jumlah int not null default 0; Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | nama | varchar(200) | NO | | NULL | | | id | int(11) | NO | | NULL | | | harga | int(11) | NO | |0 | | | jumlah | int(11) | NO | |0 | | | deskripsi | text | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
mysql> alter table barang
-> add waktu dibuat timestamp not null default current_timestamp; 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 'dibuat timestamp not null default current_timestamp' at line 2 mysql> alter table barang -> add waktu_dibuat timestamp not null default current_timestamp; Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0
mysql> desc barang;
+--------------+--------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+-------------------+-------+ | nama | varchar(200) | NO | | NULL | | | id | int(11) | NO | | NULL | | | harga | int(11) | NO | |0 | | | jumlah | int(11) | NO | |0 | | | deskripsi | text | YES | | NULL | | | waktu_dibuat | timestamp | NO | | CURRENT_TIMESTAMP | | +--------------+--------------+------+-----+-------------------+-------+ 6 rows in set (0.00 sec)
mysql> insert into barang (id, nama) values(1,"Apel");
Query OK, 1 row affected (0.01 sec)
mysql> select * from barang;
+------+----+-------+--------+-----------+---------------------+ | nama | id | harga | jumlah | deskripsi | waktu_dibuat | +------+----+-------+--------+-----------+---------------------+ | Apel | 1 | 0| 0 | NULL | 2023-01-18 21:04:12 | +------+----+-------+--------+-----------+---------------------+ 1 row in set (0.00 sec) mysql> create table barang ( -> -> id INT, -> -> nama VARCHAR(100), -> -> harga INT, -> -> jumlah INT -> -> ; 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 '-> id INT, -> nama VARCHAR(100), -> harga INT, -> jumlah INT' at line 2 mysql> CREATE TABLE products( -> id VARCHAR (100) NOT NULL, -> ; 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 2 mysql> CREATE TABLE products( -> id VARCHAR(10) NOT NULL, -> name VARCHAR(100) NOT NULL, -> description TEXT, -> price INT UNSIGNED NOT NULL, -> quantity INT UNSIGNED NOT NULL DEFAULT 0, -> created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -> )ENGINE =InnoDB; Query OK, 0 rows affected (0.03 sec)
mysql> SHOW TABLES;
+-------------------------+ | Tables_in_belajar_mysql | +-------------------------+ | barang | | products | +-------------------------+ 2 rows in set (0.00 sec)
mysql> DESC products;
+-------------+------------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+-------------------+-------+ | id | varchar(10) | NO | | NULL | | | name | varchar(100) | NO | | NULL | | | description | text | YES | | NULL | | | price | int(10) unsigned | NO | | NULL | | | quantity | int(10) unsigned | NO | |0 | | | created_at | timestamp | NO | | CURRENT_TIMESTAMP | | +-------------+------------------+------+-----+-------------------+-------+ 6 rows in set (0.01 sec)
mysql> INSERT INTO products(id,name,price,quantity)
-> ; 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 1 mysql> SELECT * FROM products -> WHERE name="P001"; Empty set (0.01 sec)
mysql> UPDATE products
-> SET category="Makanan" -> WHERE id="P001"; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0