That's possible, but there is an easier way.
(I posted this before, but it's such a rare question that I will re-post the answer just this once).
-Shutdown your MySQL.
-Move the mysql data directory from wherever it is to wherever you want it to be. (KEEP THE ORIGINAL DIRECTORY NAME!)
-Go to the directory where your mysql data directory used to be.
-Type: ln -s /new/location/of/data/directory/datadirectory
-Start MySQL
now you have moved your data, and created a symlink from the old location to the new location.
So, when you start MySQL, it will still try to access it's files in the old location. This old location is symlinked to the new location so all file operations are re-routed to the new location without any problems.