MySQL DBMS database files are saved on a hard drive. All database files are kept in the /var/lib/mysql directory by default. This course, though, can be altered.
This post will teach you how to find out where MySQL database files are located on Ubuntu 20.04.
Where can i find the MYSQL Databases?
All database files are kept in the /var/lib/mysql directory by default. To confirm this, run sudo grep -R ‘datadir’ /etc/mysql/, which will reveal the entire path to the folders where the databases are stored:
sudo grep -R 'datadir' /etc/mysql/
If you navigate to the suggested location – /var/lib/mysql – you will find all of the essential files from the databases in the directory. The operation to navigate to the folder must be run as the root user, or else the following error will occur: Permission refused
sudo su cd /var/lib/mysql ls -l
You are now aware of the location of the MySQL databases. You may also use the mysqld command with the —verbose and —help parameters to see the file storage path for the databases. This command is comparable to the one that came before it.
mysqld --verbose --help | grep ^datadir
If you need to alter the location of database files, open the MySQL configuration file as root in any text editor. As previously stated, the configuration file in this case is stored in /etc/mysql/mysql.conf.d/mysqld.cnf. The command to modify it will be as follows:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
In the opened file, look for the [mysqld] block and a parameter named datadir, where you may provide the preferred location where the databases will be placed. After you’ve set the path, you’ll need to save the changes, shut the text editor, and restart the DBMS with the command:
sudo systemctl restart mysql
In this brief post, we looked at where databases in MYSQL are kept. If necessary, you may also alter the storage directory. Do you have extensive experience with the MySQL database management system (DBMS)? Please share your thoughts in the comments section!