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

Usually is here:

/var/lib/mysql

But that depends on your configuration.


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';

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.