Monday 3 February 2020

Delete big data using MySQL Partitioning

What is MySQL Partitioning?

Partitioning is a way in which a database (MySQL in this case) splits its actual data down into separate tables, but still get treated as a single table by the SQL layer.

Partitions are also very useful in dealing with data rotation. If MySQL can easily identify rows to delete and map them to single partition, instead of running DELETE FROM table WHERE

There are 2 types of partitioning:

  1. Vertical Partitioning
  2. Horizontal Partitioning

Horizontal partitioning means that all rows matching the partitioning function will be assigned to different physical partitions. Vertical partitioning allows different table columns to be split into different physical partitions. Currently, MySQL supports horizontal partitioning, but not vertical.


Delete Millions of Records using MySql Table Partitioning Technique


Suppose we have table that have millions of records so we can ALTER the table and make table partitioning according to our needs.



Before Run any Action Query on Production Server:
1. Take backup of the table/database
2. Recommend to do this activity on low traffic (during night)
3. Perform this action on test server first before go to live server




ALTER TABLE `table_name` PARTITION BY RANGE (UNIX_TIMESTAMP(table_name_timestamp)) 
(PARTITION pYear2017 VALUES LESS THAN (UNIX_TIMESTAMP('2018-01-01 00:00:00')), 
PARTITION pYear2018 VALUES LESS THAN (UNIX_TIMESTAMP('2019-01-01 00:00:00')), 
PARTITION pYear2019 VALUES LESS THAN (MAXVALUE));


After running the above query we’ll have 3 partitions (pYear2017, pYear2018, pYear2019) of table as showing in below image.



As we can see there are many options for the Partitions. We can Analyze, Check, Optimize, Rebuild, Repair, Truncate and Drop the Partition.

We can see all the records of the selected partition using below query. I select pYear2018 partition.
This query will show all the records of year 2018



SELECT * FROM `table_name` PARTITION(pYear2018);



Now if we want to drop any partition This will also DELETE the data related to the selected partition(s). And if we truncate the partition records will delete but partition remain.


We can select any action (eg: Drop) and click on go to perform the action. Or we can run sql query by selection any partition eg: pYear2018




ALTER TABLE `table_name` DROP PARTITION pYear2018;



The above query will drop partition and delete all the records of year 2018 very fast.


We can use same technique to delete other records with other conditions as well.
This technique is very useful for the big data tables.





Tuesday 31 December 2019

Check for Palindrome string using PHP


The characters read the same backward as forward. Some examples of palindromic words are redivider, deified, civic, radar, level, rotor, kayak, reviver, racecar, redder, madam, and refer.




function palindrome($string)
{
    return strrev($string) == $string ? true : false;
} 



Results





echo palindrome('SOOS') == true ? 'This is Palindrome' : 'This is not Palindrome';

Output: This is Palindrome
Explanation: Reversing SOOS will also get SOOS





echo palindrome('SOOSS') == true ? 'This is Palindrome' : 'This is not Palindrome';

Output: This is not Palindrome
Explanation: Reversing SOOSS will get SSOOS




Thursday 3 December 2015

Basic SHELL commands (for Putty)

Overview of the most common basic SHELL commands. I typically use PuTTY, a free telnet and SSH Client for Windows and Unix platforms. It is lightweight and easy to use and doesn’t need installing (can run from a flash disk).


Navigating directories

cd
…change directory, method used for moving from one folder to another.
cd foldername/foldername2
…would take you to foldername2.
cd ..
…moves up one directory.
cd /
…moves you to root.
pwd
…prints to console your present working directory – where you currently are.

List contents

ls
…list contents of current directory.
ls -l
…shows long format inc. group owner, size, date modified, permissions.
ls -a
…shows ALL files inc. hidden files.
ls -R
…lists contents of sub directories recursively.
ls -la
…the above options can be used at the same time.
ls foldername/foldername
…list items in folder without actually moving to it.

Creating files and directories/folders

touch file.html
…use the touch command to create files.
rm file.html
…use the rm command to remove a file.
mkdir myfolder
…use the mkdir command to create a new directory/folder.
rmdir myfolder
…use the rmdir command to remove a directory/folder, folder must be empty.
mv folder1/file.html folder2/file.html
…use the mv command to move a file. Can also be used to rename a file.

Compressing and backing up files and folders

zip -r foo.zip foo/
…compress the folder ‘foo’ and all of its contents into a zip file called ‘foo.zip’.
zip foo.zip foo.html
…compress the file’foo.html’ into a zip file called ‘foo.zip’.

File and directory/folder permissions and ownership

chmod 755 file.html
…changes the file.html file permissions, same for a folder.
chmod -r 755 myfolder
…changes permissions for that folder and all folders and files inside it recursively.
Here are the chmod octal numeric values
700: only owner can read
755: everyone can read but not write
775: only group can read and write
770: no-one but group can read
666: everyone can read and write
1777: everyone can read,write,execute

chown user:myself file.html
…changes the ownership of file.html to the user called ‘myself’.

 

Tuesday 8 September 2015

MongoDB Installation + CRUD Guide

I am sharing the simplest method for MongoDB installation + db creation

Install mongodb from below link as per your OS


Go to your installed MongoDB directory/bin and create a folder with name "data"

Open cmd, go to your installed MongoDB directory/bin with the help of "cd"

execute following command:

> mongod.exe --dbpath "d:\mongo\data"  // as i have installed MongoDB in D:\mongo\ 


Wait for establishing connection

open another cmd, again go to your installed MongoDB directory/bin with the help of "cd" 

execute following command:

> mongo.exe 

Now you have access to CRUD your own db
Below is the sample code to create collection with document


> use test // it creates db with name "test"

> db.createCollection(collection_name) // it creates a Collection

> db.collection_name.insert({"name":"testing entry"})   // it creates document like "{"name":"testing entry"}"

> db.collection_name.find() // it will show all documents related to collection "collection_name"

> db.collection_name.drop() // it will delete the collection

> show dbs // it will show all databases

Note:
Mongo Db is based on no-sql. so it is bit faster 
May be there are some more professional/easy ways to do that.

Plz keep this information handy
and stay tuned, will keep sharing short articles about MeanSTACK!

Monday 7 September 2015

Express.js Running Application

There is a tutorial for installing new running Express js application!

Installing Node.js:
1- Go to this link "https://nodejs.org/" and install node.js.
2- Go to Shell and intall express generator using "npm install express-generator -g"

For New Express Application:
1- Make a directory i.e., D:\nodePractice.
2- Go to this directory and from shell "npm install express". It will create a folder in this directory called 

"node-modules".
3- Go to "node-modules" and from shell make "package.json" file using "npm init"!
While creating this file it is gonna ask for some things like appname, description, test-command etc. Enter the desired text there!
3- Go to "node-modules" directory and from shell install express application using "express" command.
4- Add This code to your app.js file created in "node-modules" directory:

var server = app.listen(3000, function() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});

5- Run app.js file!
6- intall missing modules using 'npm intall <module-name>' e.g, "npm install serve-favicon"
7- Run app.js again! Bang there you are...

Wednesday 10 September 2014

WordPress and Magento. To integrate or not


Blogging is the big part of company’s marketing activities and blog extensions are widely needed as a part of web-site. Therefore these two very powerful platforms are often integrated together. Magneto is used for  managing products, inventory, sales, payment gateways and pages, while WordPress is for blog posts.

Why WordPress?
  • First of all, there are two main reasons to add a blog to your web-site. The first is community interaction. The second is SEO content generation. And for both purposes, WordPress is the fully functional solution.
The rich SEO features built into WordPress like:
  • pingbacks, which notify your website when someone posts an article about it
  • trackbacks, which notifies a website when you post an article referencing it
These features are free at WordPress and create a rich network of backlinks. None of any Magento extensions provide these features.
  • The Magento WordPress Integration is invisible to your end user
You have the ability to customise the fields you need . WordPress  skin is identical to your Magento theme and vice versa, you can leave your CSS files and graphics in the Magento instance.
  • Flexible WordPress Plugins
There are thousands of  WordPress plugins that can improve and add the huge amount of  features and functionality to your WordPress blog.
Learn IT Delight’s successful stories based on Magento and WordPress integration:

Bringing it all together, Magento and WordPress integration  gives the user the full flexibility of WordPress and the powerful product inventory system of Magento. Building an e-Commerce store, you can use Magento as a backend and WordPress as a frontend.
WordPress blog integrated on Mangento website is the great way to promote your online store and bring more customers to your online business.

Tuesday 9 September 2014

MVC vs MVVM vs MVP

MVC vs MVVM vs MVP. What a controversial topic that many developers can spend hours and hours debating and arguing about.

For several years +AngularJS was closer to MVC (or rather one of its client-side variants), but over time and thanks to many refactorings and api improvements, it's now closer to MVVM – the $scope object could be considered the ViewModel that is being decorated by a function that we call a Controller.

Being able to categorize a framework and put it into one of the MV* buckets has some advantages. It can help developers get more comfortable with its apis by making it easier to create a mental model that represents the application that is being built with the framework. It can also help to establish terminology that is used by developers.

Having said, I'd rather see developers build kick-ass apps that are well-designed and follow separation of concerns, than see them waste time arguing about MV* nonsense. And for this reason, I hereby declare AngularJS to be MVW framework - Model-View-Whatever. Where Whatever stands for "whatever works for you".



Angular gives you a lot of flexibility to nicely separate presentation logic from business logic and presentation state. Please use it fuel your productivity and application maintainability rather than heated discussions about things that at the end of the day don't matter that much.