Josh
Josh

Reputation: 12791

Where does MySQL store .sql files by default?

I am new to MySQL and I noticed that when I connect to mysql and ask show databases; it shows a list of databases. But I am doing this from my home directory, and I don't see these files anywhere. Where does it store them/look them up by default?

I am in OS X in case it matters.

Also, if I want to completely eliminate a database, can I do this from within mysql? Or could I also go into the directory and delete the database file?

Upvotes: 2

Views: 4866

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179064

MySQL doesn't use '.sql' files. Table data files are stored as '.frm', '.ibd', '.myd', and '.myi' files, depending on the storage engine.

'.sql' is commonly used as an extension for backup files produced by mysqldump or other collections of SQL statements, but that is only a convention, and only has a meaning to the human looking at the filename. There is no "by default" on these because you have to specify where you want to save them when you make a backup of your data, which is not done by the MySQL server itself, but by a utility like mysqldump that connects to the server as a client, extracts the data, and writes it to a dump file.

MySQL's files are stored in the directory you'll find in the datadir variable.

mysql> show variables like 'datadir';
+---------------+------------------------+
| Variable_name | Value                  |
+---------------+------------------------+
| datadir       | /usr/local/mysql/data/ |
+---------------+------------------------+

Deleting files from the directories inside is generally a very bad idea, if you want the server to continue functioning. The contents of those directories should not be tinkered with unless you know exactly what you are doing and why.

If you want to delete an entire database, you use DROP DATABASE database_name;

You did read this or this, right?

Upvotes: 5

Related Questions