user637965
user637965

Reputation:

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

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?

Upvotes: 11

Views: 29543

Answers (7)

ankit singh
ankit singh

Reputation: 306

for me it was in

/opt/lampp/var/mysql/

Upvotes: 0

Rohit Maurya
Rohit Maurya

Reputation: 154

First you have to enable to show hidden Items (then open ProgramData). The go to "C:\ProgramData\MySQL\MySQL Server 8.0\Data"

Upvotes: 0

Linendra Soni
Linendra Soni

Reputation: 170

run this query

select @@datadir;

this will result somthing like this /var/lib/mysql

Upvotes: 0

Chauhan Khalid
Chauhan Khalid

Reputation: 187

Normally It is here.

/var/lib/mysql

One more thing, it is possible that you don't have permission so you can not copy database and can not take backup.

Follow this step to give permission :

  1. open terminal
  2. go to your db directory : cd /var/lib/mysql
  3. Last , sudo chmod -R 777 /var/lib/mysql

Done.

Upvotes: 0

Casper
Casper

Reputation: 34308

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

Upvotes: 4

Lepidosteus
Lepidosteus

Reputation: 12037

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.

Upvotes: 20

james_bond
james_bond

Reputation: 6908

Usually is here:

/var/lib/mysql

But that depends on your configuration.

Upvotes: 5

Related Questions