Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does mysql store data?

Tags:

mysql

Where does mysql store data? I found out (by using mysql>SELECT @@datadir ) that it's in var/lib/mysql - but that can't be it. I have a quite big database (4 GB) called 'bot', but all the files in the 'bot' subdirectory (var/lib/mysql/bot) have only 280KB. Where is the rest?

One more thing - 99% of the database's size is a text column in one of the tables - I know that mysql stores it in separate files, but does it create one file per record?

I found a big file in the var/lib/mysql directory named ibdata1 - its size is over 8GB - what is it? (btw, there are other databases as well in the var/lib/mysql directory).

like image 813
Konrad Avatar asked Oct 16 '14 11:10

Konrad


People also ask

How does MySQL store data internally?

MySQL stores each database (also called a schema) as a subdirectory of its data directory in the underlying filesystem. When you create a table, MySQL stores the table definition in a . frm file with the same name as the table. Thus, when you create a table named MyTable , MySQL stores the table definition in MyTable.

Is MySQL in memory or on disk?

MySQL offeringsIn all engines, actions are performed in RAM. The Engines differ significantly in how good they are at making sure the data "persists" on disk. ENGINE=MEMORY -- This is not persistent; the data is found only in RAM.

Where is MySQL data stored Linux?

By default, the datadir is set to /var/lib/mysql in the /etc/mysql/mysql.

Where is DB data stored?

Database tables and indexes may be stored on disk in one of a number of forms, including ordered/unordered flat files, ISAM, heap files, hash buckets, or B+ trees. Each form has its own particular advantages and disadvantages. The most commonly used forms are B-trees and ISAM.


1 Answers

From here:

Windows

  1. Locate the my.ini, which store in the MySQL installation folder.

For Example, C:\Program Files\MySQL\MySQL Server 5.1\my.ini

  1. Open the “my.ini” with our favor text editor.
#Path to installation directory. All paths are usually resolved relative to this. basedir="C:/Program Files/MySQL/MySQL Server 5.1/"   #Path to the database root datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/" 

Find the “datadir”, this is the where does MySQL stored the data in Windows.


Linux

  1. Locate the my.cnf with the find / -name my.cnf command.
yongmo@myserver:~$ find / -name my.cnf find: /home/lost+found: Permission denied find: /lost+found: Permission denied /etc/mysql/my.cnf 
  1. View the my.cnf file like this: cat /etc/mysql/my.cnf
yongmo@myserver:~$ cat /etc/mysql/my.cnf # # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. #  [mysqld] # # * Basic Settings # user   = mysql pid-file = /var/run/mysqld/mysqld.pid socket  = /var/run/mysqld/mysqld.sock port   = 3306 basedir  = /usr datadir  = /var/lib/mysql tmpdir  = /tmp language = /usr/share/mysql/english skip-external-locking 
  1. Find the “datadir”, this is where does MySQL stored the data in Linux system.
like image 170
Leo Chapiro Avatar answered Oct 07 '22 20:10

Leo Chapiro