How to find MySQL data directory name?

In this tutorial I will show you the various ways to find the data directory of a MySQL Server.

Ads

How to find MySQL data directory name?

There are various ways to find the data directory of MySQL server on Windows and Linux computers. You can follow any of the methods to find data directory of the MySQL server.

We are discussing all these methods used for finding the data directory.

Here are the methods:

Method 1: Find data directory configuration in mysql ini file which is my.in in case of Windows

Open the my.ini file and you will find the directory url where data is being stored.

So, you should find the location of MySQL installation on your windows computer and there you should be able to find the my.in file. In my case it is in the "C:\Program Files\MySQL\MySQL Server 5.5" directory of Windows 7 computer.

Here is the video tutorial of: "How to find MySQL data directory name?"

Method 2: Connect to mysql command line tools and use the following commands:

All the variables having dir in the variable name:

mysql>SHOW VARIABLES WHERE Variable_Name LIKE '%dir';

Following example shows you how to run the query and get the result:

mysql> SHOW VARIABLES WHERE Variable_Name LIKE '%dir';
  +---------------------------+---------------------------------------------------
  ------+
  | Variable_name             | Value
  |
  +---------------------------+---------------------------------------------------
  ------+
  | basedir                   | C:\Program Files\MySQL\MySQL Server 5.1\
  |
  | character_sets_dir        | C:\Program Files\MySQL\MySQL Server 5.1\share\char
  sets\ |
  | datadir                   | C:\ProgramData\MySQL\MySQL Server 5.1\Data\
  |
  | innodb_data_home_dir      |
  |
  | innodb_log_group_home_dir | .
  |
  | plugin_dir                | C:\Program Files\MySQL\MySQL Server 5.1\lib/plugin
  |
  | slave_load_tmpdir         | C:\Windows\TEMP
  |
  | tmpdir                    | C:\Windows\TEMP
  |
  +---------------------------+---------------------------------------------------
  ------+
  8 rows in set (0.00 sec)
  mysql>

Show the data dir:

mysql>SHOW VARIABLES WHERE Variable_Name = 'datadir';

**************************

mysql> SHOW VARIABLES WHERE Variable_Name = 'datadir';
  +---------------+---------------------------------------------+
  | Variable_name | Value                                       |
  +---------------+---------------------------------------------+
  | datadir       | C:\ProgramData\MySQL\MySQL Server 5.1\Data\ |
  +---------------+---------------------------------------------+
  1 row in set (0.00 sec)
  mysql>

*************************
Following query works with all the versions of MySQL

mysql> select @@datadir;

mysql> select @@datadir;
  +---------------------------------------------+
  | @@datadir                                   |
  +---------------------------------------------+
  | C:\ProgramData\MySQL\MySQL Server 5.1\Data\ |
  +---------------------------------------------+
  1 row in set (0.00 sec)
  mysql>

Method 3: Running command from command line. This is only working on Linux for me. You can type the following command on linux prompt:

if you are connect to Linux as root then you can use the following command:
mysql -e 'SHOW VARIABLES WHERE Variable_Name LIKE "%dir"'

Here is the output of the command:

[[email protected] ~]# mysql  -e 'SHOW VARIABLES WHERE Variable_Name LIKE "%dir"'
  +---------------------------+----------------------------+
  | Variable_name             | Value                      |
  +---------------------------+----------------------------+
  | basedir                   | /usr/                      |
  | bdb_logdir                |                            |
  | bdb_tmpdir                | /tmp/                      |
  | character_sets_dir        | /usr/share/mysql/charsets/ |
  | datadir                   | /var/lib/mysql/            |
  | innodb_data_home_dir      |                            |
  | innodb_log_arch_dir       |                            |
  | innodb_log_group_home_dir | ./                         |
  | slave_load_tmpdir         | /tmp/                      |
  | tmpdir                    | /tmp/                      |
  +---------------------------+----------------------------+
  [[email protected] ~]#

mysql -uroot -proot -e 'SHOW VARIABLES WHERE Variable_Name LIKE "%dir"'

I this tutorial you learned how to find the data directory of MySQL server.

Advertisements

Share on Google+Share on Google+

How to find MySQL data directory name?

Posted on: December 1, 2015 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: How to find MySQL data directory name?  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads