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

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

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 | +­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­+­­­­­+­­­­­+