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
5. • Stop MySQL
$ sudo service mysqld stop #or sudo /etc/init.d/mysqld stop
• Re-run it without ACL functionality
$ sudo mysqld_safe skipgranttables
• 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 | | 00000000 00:00:00 | |
• | created_by | int(11) | YES | | NULL | |
• | updated | timestamp | NO | | 00000000 00:00:00 | |
• | updated_by | int(11) | YES | | NULL | |
• +++++++
• 9 rows in set (0.03 sec)
•
ST: Primary Key
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 | 20151012 | 4ef8a9db5dde431e99cd493bacaeb342 |
++++++++
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 | 20151022 | df79768cb385475fb25c885a489c62fc |
++++++++
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