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

I am completely new to ubuntu and MySQL, and I created a new database via:

mysql -u root -p create database mydb; 

Now, in what directory is this database stored and how can I indicate where it was saved when I create it?

+6
source share
4 answers

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

Sort of:

 datadir = /var/lib/mysql 

Then a subdirectory is created inside each database where the contents of the database will be stored (ex: / var / lib / mysql / mydatabase). As far as I know, you cannot specify one specific database that will be stored outside of datadir.

+11
source

Usually here:

 /var/lib/mysql 

But it depends on your configuration.

+4
source

You do not need to indicate where it is stored. This is the point of using mysql. He takes care of all the database materials for you. He is set to "just work."

However, at the mysql prompt, you can use the following commands to see what happens and where:

 > status 

And for example:

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

.. or rather datadir will tell you the exact location:

 > show variables like 'datadir'; 
+1
source

Usually he is here.

 /var/lib/mysql 

In addition, it is possible that you do not have permission, so you cannot back up the database and you cannot back up.

Follow this step to give permission:

  • open terminal
  • go to db directory: cd / var / lib / mysql
  • Last one, sudo chmod -R 777 / var / lib / mysql

Done.

+1
source

Source: https://habr.com/ru/post/893111/


All Articles