Where Are MySQL Files Stored in a UNIX / Linux Harddisk

I am a new MySQL user on Unix-like systen. Where are my mysql/mariadb database and table files are stored in a UNIX or Linux operating systems? Where does MySQL stored the data in my harddisk? How do I find out the location?

Here is a simple way to find out where does MySQL or MariaDB database stored the data in our hard disk, in Linux, Unix and Windows system.

Where does MySQL stored the data in my harddisk when using Linux/Unix?

Usually /var/lib/mysql or /var/db/mysql directory used to store database and tales under UNIX like operating systems. You can use the following command to locate MySQL datadir:
grep datadir /etc/my.cnf
datadir=/var/lib/mysql

Or
grep -r datadir /etc/mysql/
Sample outputs:

/etc/mysql/mariadb.conf.d/50-server.cnf:datadir		= /var/lib/mysql

Another command that will display datadir:
ps -eo cmd,args | grep mysql
Sample outputs:

/bin/sh /usr/bin/mysqld_saf /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --user=mysql
/usr/libexec/mysqld --based /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock

Now all you have to is cd into /var/lib/mysql directory using the cd command:
$ cd /var/lib/mysql
$ ls -l

Sample outputs:

total 176196
-rw-rw---- 1 mysql mysql    16384 Aug  5 03:44 aria_log.00000001
-rw-rw---- 1 mysql mysql       52 Aug  5 03:44 aria_log_control
drwx------ 2 mysql mysql     4096 Mar  5 17:00 beta
drwx------ 2 mysql mysql     4096 Feb  5  2017 newsletter
drwx------ 2 mysql mysql     4096 Jul 14 18:14 wiki
drwx------ 2 mysql mysql     4096 Jul 25 06:15 cms
drwx------ 2 mysql mysql     4096 Jul 25 06:18 support
drwx------ 2 mysql mysql     4096 Apr 19 21:38 sales
drwx------ 2 mysql mysql     4096 Jun 24 22:29 cleandb
-rw-r--r-- 1 root  root         0 Aug  5 03:44 debian-10.0.flag
-rw-rw---- 1 mysql mysql 79691776 Aug  8 19:01 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Aug  8 19:01 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Aug  8 19:01 ib_logfile1
-rw-rw---- 1 mysql mysql        0 Jan 17  2017 multi-master.info
drwx------ 2 mysql mysql     4096 Aug  5 03:44 mysql
-rw------- 1 mysql mysql       15 Aug  5 03:44 mysql_upgrade_info
drwx------ 2 mysql mysql     4096 Aug  5 03:44 performance_schema
drwx------ 2 mysql mysql     4096 Feb  1  2017 bash
drwx------ 2 mysql mysql     4096 Jan 18  2017 nixcraft

Here is a FreeBSD UNIX specific ps command example:

ps -ao pid,command | grep mysql
Sample outputs:

 5343 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --socket=/tmp/mysql.sock --pid-file
 5381 /usr/local/libexec/mysqld --defaults-extra-file=/var/db/mysql/my.cnf --basedir=/usr/local --datadir=/var/db/mysql --user=mysql --pid-file=/var/db/mysq

Now all you have to do is cd into /var/db/mysql:
$ cd /var/db/mysql
$ ls

Find out location of data directory on MS-Windows

You need to open my.ini file. You can type the following command at cmd.exe:
cd %PROGRAMDATA%\MySQL\MySQL Server 5.7\my.ini
You need to open the my.ini file with our favor text editor such as edit or notepad:
notepad my.ini


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz