SlideShare a Scribd company logo
1 of 20
PHP Malang UG Meet Up, Nopember 2015
by Daud Mukadar
@dmukadar
Tips & Trik MySQL
$ whoami
• SLUG-er
• KLAS-er
• MPUG-er
• Accidental linux user
• Once an employee
• Freelance consultant
Daud Mukadar
• Been using PHP when GLOBAL VARIABLE 
was the thing
• Love to solve problems
• Like to write queries
• Like to learn new things
• Currently bootstraping: Tunas Mandiri IT 
Solution
• Other Trick
– Understanding join
– Partitioning
– Tree structure
• Prepare Data
• Simple tips
– forgot password
– Que on FK
– Serial as PK
– On Select
– HEAP!
On Menu Tonight
• Mockaroo.com
• GenerateData.com
• DummyData.me
• DatabaseTestData.com
Prepare Data
• Stop MySQL
$ sudo service mysqld stop #or sudo /etc/init.d/mysqld stop
• Re-run it without ACL functionality
$ sudo mysqld_safe ­­skip­grant­tables
• Hack a new password
$ mysql ­u root
mysql> use mysql;
mysql> update user set password = PASSWORD('obladi') where user = 
'root'
• Flush it
mysql> flush privileges;
• Restart
$ sudo kill `pidof mysqld_safe`
$ sudo service mysql start
ST: What's the password dude?
• Should you use it?
• joining int with int
959 rows in set (0.10 sec)
• Joining int with tiny int
119 rows in set (0.03 sec)
• Joining int with unsigned int
959 rows in set (0.05 sec)
• Joining int with varchar
959 rows in set (0.06 sec)
• Joining varchar with varchar
Empty set (1.11 sec)
ST: on Foreign Key
• Using serial
mysql> CREATE TABLE tbl_users (
id SERIAL,
username VARCHAR(40) UNIQUE,
passwd VARCHAR(32) NOT NULL,
last_login TIMESTAMP NOT NULL,
last_ip_address INT(11) UNSIGNED,
created TIMESTAMP,
created_by INT(11),
updated TIMESTAMP,
updated_by INT(11)
) engine=InnoDB;
• Result
mysql> desc tbl_users;
• +­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
• | Field           | Type                | Null | Key | Default             | Extra                       |
• +­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
• | id              | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment              |
• | username        | varchar(40)         | YES  | UNI | NULL                |                             |
• | passwd          | varchar(32)         | NO   |     | NULL                |                             |
• | last_login      | timestamp           | NO   |     | CURRENT_TIMESTAMP   | on update CURRENT_TIMESTAMP |
• | last_ip_address | int(11) unsigned    | YES  |     | NULL                |                             |
• | created         | timestamp           | NO   |     | 0000­00­00 00:00:00 |                             |
• | created_by      | int(11)             | YES  |     | NULL                |                             |
• | updated         | timestamp           | NO   |     | 0000­00­00 00:00:00 |                             |
• | updated_by      | int(11)             | YES  |     | NULL                |                             |
• +­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
• 9 rows in set (0.03 sec)
•
ST: Primary Key
• Asterisk or Not
mysql> select * from tbl_nilai where id_mhs = 958;                    
+­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| id   | id_mhs | mata_kuliah                   | semester | nilai | updated    | guid                                 |
+­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
|  464 |    958 | Ilmu ekonomi                  |        3 | 94.78 | 2015­10­01 | 7f5aeb02­ca5d­41d4­a513­51fe11c5bea6 |
|  529 |    958 | Fraud Examination             |        8 | 57.75 | 2015­10­26 | 4fc65837­bd75­424b­9f68­b04903960f1e |
| 1113 |    958 | Matematika Ekonomi            |        3 | 70.39 | 2015­10­04 | 00be5fdc­c28b­4c0a­9bf0­c3d39b2984f9 |
| 1672 |    958 | Ekonomi 2                     |        4 | 66.49 | 2015­10­03 | 5bb0f205­d746­4e60­b3c3­0cb58075d656 |
| 2169 |    958 | Manajemen Sumber Daya Manusia |        1 | 34.91 | 2015­10­08 | c0d11e1c­6204­4a46­9ef6­baecddda2ab1 |
| 2172 |    958 | Manajemen Distribusi Ritel    |        6 | 45.33 | 2015­10­18 | e7c1a632­d9e0­4655­bb4a­329a348d75c5 |
| 2193 |    958 | Studi Kelayakan Bisnis        |       13 | 59.61 | 2015­10­30 | 116ff35d­6cd0­48cb­b307­32731b3c67a6 |
| 2270 |    958 | Studi Kelayakan Bisnis        |       13 | 62.62 | 2015­10­03 | edacb7d0­25db­4dfd­8124­4bd8fd5ffb5c |
| 2668 |    958 | Evaluasi Kinerja              |       12 | 82.41 | 2015­10­06 | a465c348­966e­42de­b14a­36e635301e2a |
| 2715 |    958 | Perilaku Organisasi           |       15 | 67.66 | 2015­10­19 | f0568107­0486­408e­bef3­7cacf9663b0c |
+­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
10 rows in set (0.02 sec)
mysql> select id, id_mhs, mata_kuliah, semester, nilai, updated, guid from tbl_nilai where id_mhs = 74; 
+­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| id   | id_mhs | mata_kuliah                | semester | nilai | updated    | guid                                 |
+­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
|  879 |     74 | Manajemen Kompensasi       |       10 | 97.98 | 2015­10­13 | b8f9903f­989d­464b­bca1­7d8f689147b2 |
|  890 |     74 | Manajemen Produk & Harga   |        9 | 49.50 | 2015­10­18 | 9b036b96­888b­4e62­a158­d33ac2f3f4ba |
| 1247 |     74 | Audit 1                    |        9 | 81.01 | 2015­10­05 | c1e89f6c­28e2­4b8a­8fc2­dbeca5e1ba0d |
| 1695 |     74 | Manajemen Produk dan Harga |        8 | 39.17 | 2015­10­06 | 5e14640f­1ac6­4add­b9ca­ad1f17293dab |
| 1720 |     74 | Akuntansi Manajemen        |       16 | 93.00 | 2015­10­23 | 198f3e12­ae64­48fa­967a­8ffcc9b01338 |
| 1884 |     74 | Bahasa Inggris             |        3 |  6.96 | 2015­10­24 | 486e42a5­85f1­4a0b­96b1­6997ce705293 |
| 2475 |     74 | Pengantar Manajemen        |        7 | 28.31 | 2015­10­29 | a007b6f1­e912­4d94­963c­05094adc4c5a |
| 2611 |     74 | Audit 1                    |        3 | 55.46 | 2015­10­15 | a3613465­5967­45d7­a6a3­748915a391f6 |
| 2921 |     74 | Ekonomi 2                  |        8 | 10.14 | 2015­10­09 | d4826e58­0174­4922­9682­16ea46065923 |
| 2957 |     74 | Bahasa Inggris             |        9 | 26.33 | 2015­10­26 | 84bc611d­10dc­41aa­8297­67ff29e7ae0e |
+­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
10 rows in set (0.02 sec)
•
•
ST: On Select
• Limiting to 1
mysql> select * from tbl_nilai where id_mhs = 435;                                                     
+­­­­+­­­­­­­­+­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| id | id_mhs | mata_kuliah | semester | nilai | updated    | guid                                 |
+­­­­+­­­­­­­­+­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| 30 |    435 | Ekonomi 2   |       11 | 58.40 | 2015­10­12 | 4ef8a9db­5dde­431e­99cd­493bacaeb342 |
+­­­­+­­­­­­­­+­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
1 row in set (0.02 sec)
mysql> select * from tbl_nilai where id_mhs = 555 limit 1;
+­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| id  | id_mhs | mata_kuliah   | semester | nilai | updated    | guid                                 |
+­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| 674 |    555 | Ekonomi Makro |       11 | 61.29 | 2015­10­22 | df79768c­b385­475f­b25c­885a489c62fc |
+­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
1 row in set (0.01 sec)
ST: On Select
• MySQL DB Engine
• Storing temporary non essential value with heap
mysql> CREATE TABLE login_tracker(
user_id INT(11) NOT NULL,
login_time TIMESTAMP,
last_activity TIMESTAMP
) engine=memory;
mysql> INSERT INTO login_tracker(5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
• Heap Limitation:
–Index usage: not optimal, limited conditional operator, can not be
ordered
–No support auto increment
–Not for text or blob
ST: HEAP TO THE RESCUE
UNDERSTANDING JOIN
• Asumsi
TABLE_A       TABLE_B
id name       id  name
­­ ­­­­       ­­  ­­­­
1  Pirate     1   Rutabaga
2  Monkey     2   Pirate
3  Ninja      3   Darth Vader
4  Spaghetti  4   Ninja
• Inner Join on A.name = B.name
id name       id  name
­­ ­­­­       ­­  ­­­­
1  Pirate     2   Pirate
3  Ninja      4   Ninja
UNDERSTANDING JOIN
• Asumsi
TABLE_A       TABLE_B
id name       id  name
­­ ­­­­       ­­  ­­­­
1  Pirate     1   Rutabaga
2  Monkey     2   Pirate
3  Ninja      3   Darth Vader
4  Spaghetti  4   Ninja
• Full Outer Join on A.name = B.name
id    name       id    name
­­    ­­­­       ­­    ­­­­
1     Pirate     2     Pirate
2     Monkey     null  null
3     Ninja      4     Ninja
4     Spaghetti  null  null
null  null       1     Rutabaga
null  null       3     Darth Vader
–
UNDERSTANDING JOIN
• Asumsi
TABLE_A       TABLE_B
id name       id  name
­­ ­­­­       ­­  ­­­­
1  Pirate     1   Rutabaga
2  Monkey     2   Pirate
3  Ninja      3   Darth Vader
4  Spaghetti  4   Ninja
• Left Outer Join on A.name=B.name
id  name       id    name
­­  ­­­­       ­­    ­­­­
1   Pirate     2     Pirate
2   Monkey     null  null
3   Ninja      4     Ninja
4   Spaghetti  null  null
–
UNDERSTANDING JOIN
• Asumsi
TABLE_A       TABLE_B
id name       id  name
­­ ­­­­       ­­  ­­­­
1  Pirate     1   Rutabaga
2  Monkey     2   Pirate
3  Ninja      3   Darth Vader
4  Spaghetti  4   Ninja
• How ?
id  name       id     name
­­  ­­­­       ­­     ­­­­
2   Monkey     null   null
4   Spaghetti  null   null
–
UNDERSTANDING JOIN
• Asumsi
TABLE_A       TABLE_B
id name       id  name
­­ ­­­­       ­­  ­­­­
1  Pirate     1   Rutabaga
2  Monkey     2   Pirate
3  Ninja      3   Darth Vader
4  Spaghetti  4   Ninja
• How ?
id  name       id     name
­­  ­­­­       ­­     ­­­­
2   Monkey     null   null
4   Spaghetti  null   null
–
Partitioning
• Check Plugin
mysql> show plugins;
+­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­­­­­­­­­­+­­­­­­­­­+­­­­­­­­­+
| Name       | Status   | Type           | Library | License |
+­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­­­­­­­­­­+­­­­­­­­­+­­­­­­­­­+
| binlog     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| partition  | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| ARCHIVE    | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| BLACKHOLE  | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| CSV        | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| FEDERATED  | DISABLED | STORAGE ENGINE | NULL    | GPL     |
| MEMORY     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| InnoDB     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| MyISAM     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
| MRG_MYISAM | ACTIVE   | STORAGE ENGINE | NULL    | GPL     |
+­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­­­­­­­­­­+­­­­­­­­­+­­­­­­­­­+
10 rows in set (0.02 sec)
• Buat Partisi
CREATE TABLE tbl_patient (
    ssn VARCHAR(35),
    first_name VARCHAR(25) NOT NULL,
    last_name VARCHAR(25) NOT NULL,
    title VARCHAR(16) NOT NULL,
    dob DATE,
    registered DATE NOT NULL
)
PARTITION BY RANGE( YEAR(registered) ) (
    PARTITION p0 VALUES LESS THAN (1985),
    PARTITION p1 VALUES LESS THAN (1995),
    PARTITION p2 VALUES LESS THAN (2005),
    PARTITION p3 VALUES LESS THAN (2010),
    PARTITION p4 VALUES LESS THAN MAXVALUE
);
•
Tree Structure
• Adjency List
mysql> CREATE TABLE category(
        category_id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(20) NOT NULL,
        parent INT DEFAULT NULL
);
Mysql> SELECT * FROM category ORDER BY category_id;
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­+
| category_id | name                 | parent |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­+
|           1 | ELECTRONICS          |   NULL |
|           2 | TELEVISIONS          |      1 |
|           3 | TUBE                 |      2 |
|           4 | LCD                  |      2 |
|           5 | PLASMA               |      2 |
|           6 | PORTABLE ELECTRONICS |      1 |
|           7 | MP3 PLAYERS          |      6 |
|           8 | FLASH                |      7 |
|           9 | CD PLAYERS           |      6 |
|          10 | 2 WAY RADIOS         |      6 |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­+
10 rows in set (0.00 sec)
Tree Structure
• Nested List
mysql> CREATE TABLE nested_category (
        category_id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(20) NOT NULL,
        lft INT NOT NULL,
        rgt INT NOT NULL
);
Mysql> SELECT * FROM category ORDER BY category_id;
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
| category_id | name                 | lft | rgt |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
|           1 | ELECTRONICS          |   1 |  20 |
|           2 | TELEVISIONS          |   2 |   9 |
|           3 | TUBE                 |   3 |   4 |
|           4 | LCD                  |   5 |   6 |
|           5 | PLASMA               |   7 |   8 |
|           6 | PORTABLE ELECTRONICS |  10 |  19 |
|           7 | MP3 PLAYERS          |  11 |  14 |
|           8 | FLASH                |  12 |  13 |
|           9 | CD PLAYERS           |  15 |  16 |
|          10 | 2 WAY RADIOS         |  17 |  18 |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
Tree Structure
• Nested List
mysql> CREATE TABLE nested_category (
        category_id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(20) NOT NULL,
        lft INT NOT NULL,
        rgt INT NOT NULL
);
Mysql> SELECT * FROM category ORDER BY category_id;
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
| category_id | name                 | lft | rgt |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
|           1 | ELECTRONICS          |   1 |  20 |
|           2 | TELEVISIONS          |   2 |   9 |
|           3 | TUBE                 |   3 |   4 |
|           4 | LCD                  |   5 |   6 |
|           5 | PLASMA               |   7 |   8 |
|           6 | PORTABLE ELECTRONICS |  10 |  19 |
|           7 | MP3 PLAYERS          |  11 |  14 |
|           8 | FLASH                |  12 |  13 |
|           9 | CD PLAYERS           |  15 |  16 |
|          10 | 2 WAY RADIOS         |  17 |  18 |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
Tree Structure
• Nested List
mysql> CREATE TABLE nested_category (
        category_id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(20) NOT NULL,
        lft INT NOT NULL,
        rgt INT NOT NULL
);
Mysql> SELECT * FROM category ORDER BY category_id;
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
| category_id | name                 | lft | rgt |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
|           1 | ELECTRONICS          |   1 |  20 |
|           2 | TELEVISIONS          |   2 |   9 |
|           3 | TUBE                 |   3 |   4 |
|           4 | LCD                  |   5 |   6 |
|           5 | PLASMA               |   7 |   8 |
|           6 | PORTABLE ELECTRONICS |  10 |  19 |
|           7 | MP3 PLAYERS          |  11 |  14 |
|           8 | FLASH                |  12 |  13 |
|           9 | CD PLAYERS           |  15 |  16 |
|          10 | 2 WAY RADIOS         |  17 |  18 |
+­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+

More Related Content

Viewers also liked

Focus fast bigd15_roger_belveal_2015-09-19
Focus fast bigd15_roger_belveal_2015-09-19Focus fast bigd15_roger_belveal_2015-09-19
Focus fast bigd15_roger_belveal_2015-09-19Roger Belveal
 
Finalgraduationparty
FinalgraduationpartyFinalgraduationparty
Finalgraduationpartytonya
 
Historical processes of global change
Historical processes of global changeHistorical processes of global change
Historical processes of global changeEsthelaCaito
 
Characters from the alienist
Characters from the alienistCharacters from the alienist
Characters from the alienistEsthelaCaito
 

Viewers also liked (9)

0000border 2012
0000border 20120000border 2012
0000border 2012
 
Interventions That Work!
Interventions That Work!Interventions That Work!
Interventions That Work!
 
Amal v20-3
Amal v20-3Amal v20-3
Amal v20-3
 
Focus fast bigd15_roger_belveal_2015-09-19
Focus fast bigd15_roger_belveal_2015-09-19Focus fast bigd15_roger_belveal_2015-09-19
Focus fast bigd15_roger_belveal_2015-09-19
 
Finalgraduationparty
FinalgraduationpartyFinalgraduationparty
Finalgraduationparty
 
Historical processes of global change
Historical processes of global changeHistorical processes of global change
Historical processes of global change
 
Marriage in india
Marriage in indiaMarriage in india
Marriage in india
 
Characters from the alienist
Characters from the alienistCharacters from the alienist
Characters from the alienist
 
High School Math and Reading Readiness
High School Math and Reading ReadinessHigh School Math and Reading Readiness
High School Math and Reading Readiness
 

Similar to Php meetup-nop2015

The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux AdminThe Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux AdminDave Stokes
 
Better encryption & security with MariaDB 10.1 & MySQL 5.7
Better encryption & security with MariaDB 10.1 & MySQL 5.7Better encryption & security with MariaDB 10.1 & MySQL 5.7
Better encryption & security with MariaDB 10.1 & MySQL 5.7Colin Charles
 
MariaDB Server & MySQL Security Essentials 2016
MariaDB Server & MySQL Security Essentials 2016MariaDB Server & MySQL Security Essentials 2016
MariaDB Server & MySQL Security Essentials 2016Colin Charles
 
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsLinuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsDave Stokes
 
Installing Moodle is Easy
Installing Moodle is EasyInstalling Moodle is Easy
Installing Moodle is EasysimonsCatalyst
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsProper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsDave Stokes
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...Dave Stokes
 

Similar to Php meetup-nop2015 (8)

The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux AdminThe Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
The Peoper Care and Feeding of a MySQL Server for Busy Linux Admin
 
Better encryption & security with MariaDB 10.1 & MySQL 5.7
Better encryption & security with MariaDB 10.1 & MySQL 5.7Better encryption & security with MariaDB 10.1 & MySQL 5.7
Better encryption & security with MariaDB 10.1 & MySQL 5.7
 
MariaDB Server & MySQL Security Essentials 2016
MariaDB Server & MySQL Security Essentials 2016MariaDB Server & MySQL Security Essentials 2016
MariaDB Server & MySQL Security Essentials 2016
 
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux AdminsLinuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
Linuxfest Northwest Proper Care and Feeding Of a MySQL for Busy Linux Admins
 
Running SQL Queries on the Moodle Database
Running SQL Queries on the Moodle DatabaseRunning SQL Queries on the Moodle Database
Running SQL Queries on the Moodle Database
 
Installing Moodle is Easy
Installing Moodle is EasyInstalling Moodle is Easy
Installing Moodle is Easy
 
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux AdministratorsProper Care and Feeding of a MySQL Database for Busy Linux Administrators
Proper Care and Feeding of a MySQL Database for Busy Linux Administrators
 
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
The Proper Care and Feeding of a MySQL Database for Busy Linux Admins -- SCaL...
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Php meetup-nop2015

  • 1. PHP Malang UG Meet Up, Nopember 2015 by Daud Mukadar @dmukadar Tips & Trik MySQL
  • 2. $ whoami • SLUG-er • KLAS-er • MPUG-er • Accidental linux user • Once an employee • Freelance consultant Daud Mukadar • Been using PHP when GLOBAL VARIABLE  was the thing • Love to solve problems • Like to write queries • Like to learn new things • Currently bootstraping: Tunas Mandiri IT  Solution
  • 3. • Other Trick – Understanding join – Partitioning – Tree structure • Prepare Data • Simple tips – forgot password – Que on FK – Serial as PK – On Select – HEAP! On Menu Tonight
  • 4. • Mockaroo.com • GenerateData.com • DummyData.me • DatabaseTestData.com Prepare Data
  • 5. • Stop MySQL $ sudo service mysqld stop #or sudo /etc/init.d/mysqld stop • Re-run it without ACL functionality $ sudo mysqld_safe ­­skip­grant­tables • Hack a new password $ mysql ­u root mysql> use mysql; mysql> update user set password = PASSWORD('obladi') where user =  'root' • Flush it mysql> flush privileges; • Restart $ sudo kill `pidof mysqld_safe` $ sudo service mysql start ST: What's the password dude?
  • 6. • Should you use it? • joining int with int 959 rows in set (0.10 sec) • Joining int with tiny int 119 rows in set (0.03 sec) • Joining int with unsigned int 959 rows in set (0.05 sec) • Joining int with varchar 959 rows in set (0.06 sec) • Joining varchar with varchar Empty set (1.11 sec) ST: on Foreign Key
  • 7. • Using serial mysql> CREATE TABLE tbl_users ( id SERIAL, username VARCHAR(40) UNIQUE, passwd VARCHAR(32) NOT NULL, last_login TIMESTAMP NOT NULL, last_ip_address INT(11) UNSIGNED, created TIMESTAMP, created_by INT(11), updated TIMESTAMP, updated_by INT(11) ) engine=InnoDB; • Result mysql> desc tbl_users; • +­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ • | Field           | Type                | Null | Key | Default             | Extra                       | • +­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ • | id              | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment              | • | username        | varchar(40)         | YES  | UNI | NULL                |                             | • | passwd          | varchar(32)         | NO   |     | NULL                |                             | • | last_login      | timestamp           | NO   |     | CURRENT_TIMESTAMP   | on update CURRENT_TIMESTAMP | • | last_ip_address | int(11) unsigned    | YES  |     | NULL                |                             | • | created         | timestamp           | NO   |     | 0000­00­00 00:00:00 |                             | • | created_by      | int(11)             | YES  |     | NULL                |                             | • | updated         | timestamp           | NO   |     | 0000­00­00 00:00:00 |                             | • | updated_by      | int(11)             | YES  |     | NULL                |                             | • +­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­+­­­­­+­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ • 9 rows in set (0.03 sec) • ST: Primary Key
  • 8. • Asterisk or Not mysql> select * from tbl_nilai where id_mhs = 958;                     +­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | id   | id_mhs | mata_kuliah                   | semester | nilai | updated    | guid                                 | +­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ |  464 |    958 | Ilmu ekonomi                  |        3 | 94.78 | 2015­10­01 | 7f5aeb02­ca5d­41d4­a513­51fe11c5bea6 | |  529 |    958 | Fraud Examination             |        8 | 57.75 | 2015­10­26 | 4fc65837­bd75­424b­9f68­b04903960f1e | | 1113 |    958 | Matematika Ekonomi            |        3 | 70.39 | 2015­10­04 | 00be5fdc­c28b­4c0a­9bf0­c3d39b2984f9 | | 1672 |    958 | Ekonomi 2                     |        4 | 66.49 | 2015­10­03 | 5bb0f205­d746­4e60­b3c3­0cb58075d656 | | 2169 |    958 | Manajemen Sumber Daya Manusia |        1 | 34.91 | 2015­10­08 | c0d11e1c­6204­4a46­9ef6­baecddda2ab1 | | 2172 |    958 | Manajemen Distribusi Ritel    |        6 | 45.33 | 2015­10­18 | e7c1a632­d9e0­4655­bb4a­329a348d75c5 | | 2193 |    958 | Studi Kelayakan Bisnis        |       13 | 59.61 | 2015­10­30 | 116ff35d­6cd0­48cb­b307­32731b3c67a6 | | 2270 |    958 | Studi Kelayakan Bisnis        |       13 | 62.62 | 2015­10­03 | edacb7d0­25db­4dfd­8124­4bd8fd5ffb5c | | 2668 |    958 | Evaluasi Kinerja              |       12 | 82.41 | 2015­10­06 | a465c348­966e­42de­b14a­36e635301e2a | | 2715 |    958 | Perilaku Organisasi           |       15 | 67.66 | 2015­10­19 | f0568107­0486­408e­bef3­7cacf9663b0c | +­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ 10 rows in set (0.02 sec) mysql> select id, id_mhs, mata_kuliah, semester, nilai, updated, guid from tbl_nilai where id_mhs = 74;  +­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | id   | id_mhs | mata_kuliah                | semester | nilai | updated    | guid                                 | +­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ |  879 |     74 | Manajemen Kompensasi       |       10 | 97.98 | 2015­10­13 | b8f9903f­989d­464b­bca1­7d8f689147b2 | |  890 |     74 | Manajemen Produk & Harga   |        9 | 49.50 | 2015­10­18 | 9b036b96­888b­4e62­a158­d33ac2f3f4ba | | 1247 |     74 | Audit 1                    |        9 | 81.01 | 2015­10­05 | c1e89f6c­28e2­4b8a­8fc2­dbeca5e1ba0d | | 1695 |     74 | Manajemen Produk dan Harga |        8 | 39.17 | 2015­10­06 | 5e14640f­1ac6­4add­b9ca­ad1f17293dab | | 1720 |     74 | Akuntansi Manajemen        |       16 | 93.00 | 2015­10­23 | 198f3e12­ae64­48fa­967a­8ffcc9b01338 | | 1884 |     74 | Bahasa Inggris             |        3 |  6.96 | 2015­10­24 | 486e42a5­85f1­4a0b­96b1­6997ce705293 | | 2475 |     74 | Pengantar Manajemen        |        7 | 28.31 | 2015­10­29 | a007b6f1­e912­4d94­963c­05094adc4c5a | | 2611 |     74 | Audit 1                    |        3 | 55.46 | 2015­10­15 | a3613465­5967­45d7­a6a3­748915a391f6 | | 2921 |     74 | Ekonomi 2                  |        8 | 10.14 | 2015­10­09 | d4826e58­0174­4922­9682­16ea46065923 | | 2957 |     74 | Bahasa Inggris             |        9 | 26.33 | 2015­10­26 | 84bc611d­10dc­41aa­8297­67ff29e7ae0e | +­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ 10 rows in set (0.02 sec) • • ST: On Select
  • 9. • Limiting to 1 mysql> select * from tbl_nilai where id_mhs = 435;                                                      +­­­­+­­­­­­­­+­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | id | id_mhs | mata_kuliah | semester | nilai | updated    | guid                                 | +­­­­+­­­­­­­­+­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | 30 |    435 | Ekonomi 2   |       11 | 58.40 | 2015­10­12 | 4ef8a9db­5dde­431e­99cd­493bacaeb342 | +­­­­+­­­­­­­­+­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ 1 row in set (0.02 sec) mysql> select * from tbl_nilai where id_mhs = 555 limit 1; +­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | id  | id_mhs | mata_kuliah   | semester | nilai | updated    | guid                                 | +­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | 674 |    555 | Ekonomi Makro |       11 | 61.29 | 2015­10­22 | df79768c­b385­475f­b25c­885a489c62fc | +­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ 1 row in set (0.01 sec) ST: On Select
  • 10. • MySQL DB Engine • Storing temporary non essential value with heap mysql> CREATE TABLE login_tracker( user_id INT(11) NOT NULL, login_time TIMESTAMP, last_activity TIMESTAMP ) engine=memory; mysql> INSERT INTO login_tracker(5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); • Heap Limitation: –Index usage: not optimal, limited conditional operator, can not be ordered –No support auto increment –Not for text or blob ST: HEAP TO THE RESCUE
  • 12. UNDERSTANDING JOIN • Asumsi TABLE_A       TABLE_B id name       id  name ­­ ­­­­       ­­  ­­­­ 1  Pirate     1   Rutabaga 2  Monkey     2   Pirate 3  Ninja      3   Darth Vader 4  Spaghetti  4   Ninja • Full Outer Join on A.name = B.name id    name       id    name ­­    ­­­­       ­­    ­­­­ 1     Pirate     2     Pirate 2     Monkey     null  null 3     Ninja      4     Ninja 4     Spaghetti  null  null null  null       1     Rutabaga null  null       3     Darth Vader –
  • 13. UNDERSTANDING JOIN • Asumsi TABLE_A       TABLE_B id name       id  name ­­ ­­­­       ­­  ­­­­ 1  Pirate     1   Rutabaga 2  Monkey     2   Pirate 3  Ninja      3   Darth Vader 4  Spaghetti  4   Ninja • Left Outer Join on A.name=B.name id  name       id    name ­­  ­­­­       ­­    ­­­­ 1   Pirate     2     Pirate 2   Monkey     null  null 3   Ninja      4     Ninja 4   Spaghetti  null  null –
  • 16. Partitioning • Check Plugin mysql> show plugins; +­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­­­­­­­­­­+­­­­­­­­­+­­­­­­­­­+ | Name       | Status   | Type           | Library | License | +­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­­­­­­­­­­+­­­­­­­­­+­­­­­­­­­+ | binlog     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | partition  | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | ARCHIVE    | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | BLACKHOLE  | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | CSV        | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | FEDERATED  | DISABLED | STORAGE ENGINE | NULL    | GPL     | | MEMORY     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | InnoDB     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | MyISAM     | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | | MRG_MYISAM | ACTIVE   | STORAGE ENGINE | NULL    | GPL     | +­­­­­­­­­­­­+­­­­­­­­­­+­­­­­­­­­­­­­­­­+­­­­­­­­­+­­­­­­­­­+ 10 rows in set (0.02 sec) • Buat Partisi CREATE TABLE tbl_patient (     ssn VARCHAR(35),     first_name VARCHAR(25) NOT NULL,     last_name VARCHAR(25) NOT NULL,     title VARCHAR(16) NOT NULL,     dob DATE,     registered DATE NOT NULL ) PARTITION BY RANGE( YEAR(registered) ) (     PARTITION p0 VALUES LESS THAN (1985),     PARTITION p1 VALUES LESS THAN (1995),     PARTITION p2 VALUES LESS THAN (2005),     PARTITION p3 VALUES LESS THAN (2010),     PARTITION p4 VALUES LESS THAN MAXVALUE ); •
  • 17. Tree Structure • Adjency List mysql> CREATE TABLE category(         category_id INT AUTO_INCREMENT PRIMARY KEY,         name VARCHAR(20) NOT NULL,         parent INT DEFAULT NULL ); Mysql> SELECT * FROM category ORDER BY category_id; +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­+ | category_id | name                 | parent | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­+ |           1 | ELECTRONICS          |   NULL | |           2 | TELEVISIONS          |      1 | |           3 | TUBE                 |      2 | |           4 | LCD                  |      2 | |           5 | PLASMA               |      2 | |           6 | PORTABLE ELECTRONICS |      1 | |           7 | MP3 PLAYERS          |      6 | |           8 | FLASH                |      7 | |           9 | CD PLAYERS           |      6 | |          10 | 2 WAY RADIOS         |      6 | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­+ 10 rows in set (0.00 sec)
  • 18. Tree Structure • Nested List mysql> CREATE TABLE nested_category (         category_id INT AUTO_INCREMENT PRIMARY KEY,         name VARCHAR(20) NOT NULL,         lft INT NOT NULL,         rgt INT NOT NULL ); Mysql> SELECT * FROM category ORDER BY category_id; +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+ | category_id | name                 | lft | rgt | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+ |           1 | ELECTRONICS          |   1 |  20 | |           2 | TELEVISIONS          |   2 |   9 | |           3 | TUBE                 |   3 |   4 | |           4 | LCD                  |   5 |   6 | |           5 | PLASMA               |   7 |   8 | |           6 | PORTABLE ELECTRONICS |  10 |  19 | |           7 | MP3 PLAYERS          |  11 |  14 | |           8 | FLASH                |  12 |  13 | |           9 | CD PLAYERS           |  15 |  16 | |          10 | 2 WAY RADIOS         |  17 |  18 | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
  • 19. Tree Structure • Nested List mysql> CREATE TABLE nested_category (         category_id INT AUTO_INCREMENT PRIMARY KEY,         name VARCHAR(20) NOT NULL,         lft INT NOT NULL,         rgt INT NOT NULL ); Mysql> SELECT * FROM category ORDER BY category_id; +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+ | category_id | name                 | lft | rgt | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+ |           1 | ELECTRONICS          |   1 |  20 | |           2 | TELEVISIONS          |   2 |   9 | |           3 | TUBE                 |   3 |   4 | |           4 | LCD                  |   5 |   6 | |           5 | PLASMA               |   7 |   8 | |           6 | PORTABLE ELECTRONICS |  10 |  19 | |           7 | MP3 PLAYERS          |  11 |  14 | |           8 | FLASH                |  12 |  13 | |           9 | CD PLAYERS           |  15 |  16 | |          10 | 2 WAY RADIOS         |  17 |  18 | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+
  • 20. Tree Structure • Nested List mysql> CREATE TABLE nested_category (         category_id INT AUTO_INCREMENT PRIMARY KEY,         name VARCHAR(20) NOT NULL,         lft INT NOT NULL,         rgt INT NOT NULL ); Mysql> SELECT * FROM category ORDER BY category_id; +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+ | category_id | name                 | lft | rgt | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+ |           1 | ELECTRONICS          |   1 |  20 | |           2 | TELEVISIONS          |   2 |   9 | |           3 | TUBE                 |   3 |   4 | |           4 | LCD                  |   5 |   6 | |           5 | PLASMA               |   7 |   8 | |           6 | PORTABLE ELECTRONICS |  10 |  19 | |           7 | MP3 PLAYERS          |  11 |  14 | |           8 | FLASH                |  12 |  13 | |           9 | CD PLAYERS           |  15 |  16 | |          10 | 2 WAY RADIOS         |  17 |  18 | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+