Wednesday, November 2, 2011

NOTA MYSQL 17HB

MYSQL DATABASE SERVER
=====================




Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>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.5.16 MySQL Community Server (GPL)

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>

Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.16 MySQL Community Server (GPL)

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> $ mysql -u root -p
-> ;
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 '$ mys
ql -u root -p' at line 1
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

mysql> use information_schema;
Database changed
mysql> use msql;
ERROR 1049 (42000): Unknown database 'msql'
mysql> use mysql;
Database changed

mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)

mysql> select interval 1 day + '2009-12-31';
+-------------------------------+
| interval 1 day + '2009-12-31' |
+-------------------------------+
| 2010-01-01 |
+-------------------------------+
1 row in set (0.00 sec)

mysql> select '2010-01-01'-interval 1 second;
+--------------------------------+
| '2010-01-01'-interval 1 second |
+--------------------------------+
| 2009-12-31 23:59:59 |
+--------------------------------+
1 row in set (0.00 sec)

mysql> select date_add('2009-12-31 23:59:59', interval 1 second);
+----------------------------------------------------+
| date_add('2009-12-31 23:59:59', interval 1 second) |
+----------------------------------------------------+
| 2010-01-01 00:00:00 |
+----------------------------------------------------+
1 row in set (0.00 sec)

mysql> select date_sub('2010-01-01 00:00:00', interval '1 1:1:1' DAY_SECOND);
+----------------------------------------------------------------+
| date_sub('2010-01-01 00:00:00', interval '1 1:1:1' DAY_SECOND) |
+----------------------------------------------------------------+
| 2009-12-30 22:58:59 |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT DATE_SUB('2010-01-02', INTERVAL 31 DAY);
+-----------------------------------------+
| DATE_SUB('2010-01-02', INTERVAL 31 DAY) |
+-----------------------------------------+
| 2009-12-02 |
+-----------------------------------------+
1 row in set (0.00 sec)

mysql> select datediff(now(),'1967-07-12')/365 as 'year\'s old';
+------------+
| year's old |
+------------+
| 44.2959 |
+------------+
1 row in set (0.00 sec)

mysql> select ceil(datediff(now(),'1967-07-12')/365) as 'year\'s old';
+------------+
| year's old |
+------------+
| 45 |
+------------+
1 row in set (0.00 sec)

mysql> select floor(datediff(now(),'1967-07-12')/365) as 'year\'s old';
+------------+
| year's old |
+------------+
| 44 |
+------------+
1 row in set (0.00 sec)

mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2011-10-17 |
+------------+
1 row in set (0.00 sec)

mysql> select week(current_date()) as 'This is week';
+--------------+
| This is week |
+--------------+
| 42 |
+--------------+
1 row in set (0.00 sec)

mysql> select week(current_date());
+----------------------+
| week(current_date()) |
+----------------------+
| 42 |
+----------------------+
1 row in set (0.00 sec)

mysql> select concat_ws('-', 'Salam', 'Sejahtera');
+--------------------------------------+
| concat_ws('-', 'Salam', 'Sejahtera') |
+--------------------------------------+
| Salam-Sejahtera |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> select concat_ws(' ', 'Salam', 'sejahtera', ',', 'semua');
+----------------------------------------------------+
| concat_ws(' ', 'Salam', 'sejahtera', ',', 'semua') |
+----------------------------------------------------+
| Salam sejahtera , semua |
+----------------------------------------------------+
1 row in set (0.00 sec)

mysql> select concat_ws(' ', 'Salam', 'sejahtera,', 'semua');
+------------------------------------------------+
| concat_ws(' ', 'Salam', 'sejahtera,', 'semua') |
+------------------------------------------------+
| Salam sejahtera, semua |
+------------------------------------------------+
1 row in set (0.00 sec)

mysql>
mysql> select concat_ws(' ', 'Salam', 'sejahtera,', 'semua');
+------------------------------------------------+
| concat_ws(' ', 'Salam', 'sejahtera,', 'semua') |
+------------------------------------------------+
| Salam sejahtera, semua |
+------------------------------------------------+
1 row in set (0.00 sec)

mysql> select concat_ws(' ', 'Salam', 'sejahtera,', 'semua');
+------------------------------------------------+
| concat_ws(' ', 'Salam', 'sejahtera,', 'semua') |
+------------------------------------------------+
| Salam sejahtera, semua |
+------------------------------------------------+
1 row in set (0.00 sec)

mysql> create database uniclub;
Query OK, 1 row affected (0.00 sec)

mysql> use uniclub;
Database changed
mysql> create table students(
-> student_id varchar(32) not null primary key,
-> matrix_no varchar(10) not null,
-> full_name varchar(15));
Query OK, 0 rows affected (0.06 sec)

mysql> create table clubs(
-> club_id varchar(32) not null primary key,
-> est_date date not null,
-> club_name varchar(50) not null,
-> supervisor_id varchar(32) not null);
Query OK, 0 rows affected (0.06 sec)

mysql> create table lectures (
-> lesturer_id varchar(32) not null primary key,
-> staff_no varchar(10) not null,
-> full_name varchar(100) not null);
Query OK, 0 rows affected (0.05 sec)

mysql> create table activities (
-> activity_id varchar(32) not null primary key,
-> start datetime,
-> end datetime,
-> venue varchar(100),
-> club_id varchar(32) not null);
Query OK, 0 rows affected (0.06 sec)

mysql> create table students_clubs (
-> student_id varchar(32) not null,
-> club_id varchar(32) not null);
Query OK, 0 rows affected (0.08 sec)

mysql> create table students_activities (
-> student_id varchar(32) not null,
-> club_id varchar(32) not null);
Query OK, 0 rows affected (0.08 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| uniclub |
+--------------------+
5 rows in set (0.00 sec)

mysql> use uniclub;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_uniclub |
+---------------------+
| activities |
| clubs |
| lectures |
| students |
| students_activities |
| students_clubs |
+---------------------+
6 rows in set (0.00 sec)

mysql> describe students;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| student_id | varchar(32) | NO | PRI | NULL | |
| matrix_no | varchar(10) | NO | | NULL | |
| full_name | varchar(15) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table students add phone varchar(15) not null;
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> describe students;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| student_id | varchar(32) | NO | PRI | NULL | |
| matrix_no | varchar(10) | NO | | NULL | |
| full_name | varchar(15) | YES | | NULL | |
| phone | varchar(15) | NO | | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

No comments:

Post a Comment