where is my database saved when I create it in MySQL?

24,459

Solution 1

In your mysql configuration file (usually /etc/mysql/my.cnf) you should have a datadir property, which is the location where mysql will save its data

Something like:

datadir = /var/lib/mysql

It then creates a subdirectory inside that for each database where it will store the database content (ex: /var/lib/mysql/mydatabase). As far as I know, you can't specify one particular database to be stored outside of datadir.

Solution 2

Usually is here:

/var/lib/mysql

But that depends on your configuration.

Solution 3

You shouldn't need to specify where it is saved. That's the point of using mysql. It takes care of all the databasy stuff for you. It comes preconfigured to "just work".

However in the mysql prompt you can use the following commands to look into what is happening and where:

> status

And for example:

> show variables;
> show variables like '%dir%';

..and more specifically datadir will tell you the exact location:

> show variables like 'datadir';
Share:
24,459
Admin
Author by

Admin

Updated on May 15, 2021

Comments

  • Admin
    Admin about 3 years

    I'm completely new to ubuntu and MySQL and I created a new database via:

    mysql -u root -p
    create database mydb;
    

    Now, in which directory is this database saved and how do I specify where it's saved when I create it?

  • TheKitMurkit
    TheKitMurkit over 6 years
    Linux mint config file location: /etc/mysql/mysql.conf.d/mysqld.cnf