[ubuntu]

MySQLisawidelyusedandfastSQLdatabaseserver.Itisaclient/serverimplementationthatconsistsofaserverdaemon(mysqld)andmanydifferentclientprograms/libraries.

IfyouwanttoinstallMysqldatabaseserverinUbuntucheckthistutorial.

WhatisMysqlDataDirectory?

Mysqldatadirectoryisimportantpartwhereallthemysqldatabasesstoragelocation.BydefaultMySQLdatadefaultdirectorylocatedin/var/lib/mysql.Ifyouarerunningoutofspacein/varpartitionyouneedtomovethistosomeotherlocation.

Note:-Thisisonlyforadvancedusersandbeforemovingdefaultdirectorymakeabackupofyourmysaldatabases.

Proceduretofollow

Opentheterminal

FirstyouneedtoStopMySQLusingthefollowingcommand

sudo/etc/init.d/mysqlstop

NowCopytheexistingdatadirectory(defaultlocatedin/var/lib/mysql)usingthefollowingcommand

sudocp-R-p/var/lib/mysql/path/to/new/datadir

Allyouneedarethedatafiles,sodeletetheotherswiththecommand

sudorm/path/to/new/datadir

Note:-Youwillgetamessageaboutnotbeingabletodeletesomedirectories,butthat'swhatyouwant.

NowedittheMySQLconfigurationfilewiththefollowingcommand

gksugedit/etc/mysql/my.cnf

Lookfortheentryfor"datadir",andchangethepath(whichshouldbe"/var/lib/mysql")tothenewdatadirectory.

ImportantNote:-FromUbuntu7.10(GutsyGibbon)forward,UbuntuusessomesecuritysoftwarecalledAppArmorthatspecifiestheareasofyourfilesystemapplicationsareallowedtoaccess.UnlessyoumodifytheAppArmorprofileforMySQL,you'llneverbeabletorestartMySQLwiththenewdatadirlocation.

Intheterminal,enterthecommand

sudogedit/etc/apparmor.d/usr.sbin.mysqld

Copythelinesbeginningwith"/var/lib/mysql",commentouttheoriginalswithhashmarks("#"),andpastethelinesbelowtheoriginals.

Nowchange"/var/lib/mysql"inthetwonewlineswith"/path/to/new/datadir".Saveandclosethefile.

RestarttheAppArmorprofileswiththecommand

sudo/etc/init.d/apparmorreload

(sudovim/etc/init/mysql.confchange/var/lib/mysqltoyournewpath)

RestartMySQLwiththecommand

sudo/etc/init.d/mysqlrestart

or

sudostartmysql

(iffails,trysudochown-Rmysql:mysql/path/to/new/datadir)

NowMySQLshouldstartwithnoerrors,andyourdatawillbestoredinthenewdatadirectorylocation.