網頁

2013年6月14日 星期五

MySQL --- How to know the location of the default or custom database

If we are system manager and have to install MySQL on CentOS, we always know the default data directory location will depend on the installed method. For example,
      If install MySQL from a source distribution(*.tar.gz), its default data location is “/usr/local/mysql/var”.
      If install MySQL from a binary distribution, its default data location is “/usr/local/mysql/data”.
      If install MySQL from a RPM file(*.rpm), its default data location is “/var/lib/mysql”.

But if we take over MySQL management after the system and database is installed by someone, how to know the location of default or custom database?

In system console, log on SQL console and type sql command as show databases; to show which databases need to be realized.
ScreenHunter_03According to database path rule, by default all database files are located under the default location as /var/lib/mysql/"db_name", we can use find / –name “db_name” –print command to find out the special database path.
ScreenHunter_06
To do the find command again but change search path from / to found path as /var/lib/mysql/emdp, we can realize whether the file type belong to MySQL data format(*.frm).ScreenHunter_01Finally, if we want to know the default data directory on MySQL now,we can use sql command as SHOW VARIABLES LIKE ‘datadir’;ScreenHunter_04or mysqladmin command as mysqladmin –u root –p variables | grep datadir
ScreenHunter_05

沒有留言:

張貼留言

Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.