How To Find Mysql Installation Path In Linux
By default, the MySQL/MariaDB SQL database servers put their information on the root filesystem. This is not what you want in your product servers most of time. You may desire to put the database server data to a unlike difficult drive or SSD partition.
In this commodity, I am going to bear witness you how to modify the MySQL/MariaDB database'south default data directory on Ubuntu. So, let'due south get started.
Installing MySQL/MariaDB on Ubuntu:
MySQL/MariaDB database packages are bachelor in the official Ubuntu package repository. So, you can easily install it from there using the APT package manager.
Starting time, update the APT packet repository cache with the following control:
Now, if you want to install MySQL database server, run the following command:
$ sudo apt install mysql-server mysql-client
If you lot want to install MariaDB database server, run the following command:
$ sudo apt install mariadb-server mariadb-client
I am going to install MariaDB database server in this commodity. You tin can install MySQL if y'all desire.
Once you run the required installation command, you should meet the following prompt. Press y then press <Enter> to continue.
MySQL/MariaDB database server should be installed.
Finding the Default MySQL/MariaDB Data Directory:
You lot can find the default data directory of MySQL/MariaDB database very easily with the grep or egrep command.
$ sudo grep -R --color datadir /etc/mysql/*
As yous can see, the default data directory for the MariaDB database server is /var/lib/mysql. The configuration file of MariaDB database server is /etc/mysql/mariadb.conf.d/50-server.cnf. If you desire to change the default information directory of the MariaDB database server, then you have to change it in the configuration file /etc/mysql/mariadb.conf.d/50-server.cnf.
The default information directory for the MySQL database server is /var/lib/mysql also. But the configuration file is different for MySQL database server. For MySQL, the configuration file is /etc/mysql/mysql.conf.d/mysqld.cnf. If yous've installed MySQL database server, and so to change the default data directory, you take to modify this configuration file.
In the next sections, I am going to show yous how to set a hd or SSD partition for MySQL/MariaDB data directory and change the default information directory.
Preparing MySQL/MariaDB Data Directory:
In this section, I am going to bear witness you lot how to ready your Hard Deejay or SSD partition for MySQL/MariaDB information directory.
You tin can listing all the installed difficult drives or SSDs on your computer with the post-obit command:
All the installed hard drives and SSDs should exist listed. sdb is the hard bulldoze where I desire to put my MySQL/MariaDB data. Yours should be different. So, supercede information technology with yours from now on.
Now, yous have to make a new partition on the hard drive sdb with fdisk.
Annotation: In this section, I won't become through the details on how fdisk work. To larn how to partition difficult drives or SSDs with fdisk, read the article How to Employ fdisk in Linux.
To brand a sectionalization on the hard drive sdb, open it with fdisk as follows:
Now, press n so press <Enter>.
Now, press p and and so press <Enter>.
Now, press <Enter>.
Press <Enter>.
Printing <Enter>. A new sectionalisation should exist created.
Now, press due west and press <Enter>.
Permit'south say, the hard drive partition you desire to use as the MySQL/MariaDB data directory is /dev/sdb1.
Now, format the sectionalization /dev/sdb1 with the following command:
$ sudo mkfs.ext4 -L db_data /dev/sdb1
Now, make a new directory /db for moutning the /dev/sdb1 sectionalization.
/db will be the new data directory of MySQL/MariaDB.
At present, open up /etc/fstab file with the post-obit control:
Now, add the following line at the end of the file and save the file by pressing <Ctrl> + x followed past y and <Enter>.
/dev/sdb1 /db ext4 defaults 0 0
Now reboot your estimator with the following control:
Once your computer boots, /dev/sdb1 should be mounted on /db equally y'all tin see in the screenshot below.
Now, change the owner and group of the /db directory to mysql with the following control:
$ sudo chown mysql:mysql /db
At present, you have to stop MySQL/MariaDB database service and copy all the files from the default information directory /var/lib/mysql to the new data directory /db.
If you're using MariaDB, then stop MariaDB service with the following command:
$ sudo systemctl stop mariadb
If you're using MySQL, and so stop MySQL service with the post-obit command:
$ sudo systemctl stop mysql
Now, re-create all the contents of the default data directory /var/lib/mysql to the new information directory /db with the post-obit command:
$ sudo rsync -avzh /var/lib/mysql/ /db
All the contents of /var/lib/mysql directory should be copied to the new directory /db.
/db directory is now prepared to be the new MySQL/MariaDB data directory.
Configuring AppArmor:
Now, you have to configure AppArmor to allow /db to be a MySQL/MariaDB data directory.
To practise that, edit the AppArmor allonym file /etc/apparmor.d/tunables/alias equally follows:
$ sudo nano /etc/apparmor.d/tunables/ alias
At present, add the following line at the cease of the file and save it past pressing <Ctrl> + x followed by y and <Enter>.
allonym /var/lib/mysql -> /db,
At present, restart apparmor service with the following command:
$ sudo systemctl restart apparmor
Now, y'all're set up to change the data directory of MySQL/MariaDB.
Irresolute MySQL/MariaDB Information Directory:
To change the data directory from /var/lib/mysql to /db, yous accept to edit the required configuration file depending on whether you lot're using MySQL/MariaDB.
If yous're using MariaDB, and then the configuration file you have to edit is /etc/mysql/mariadb.conf.d/50-server.cnf.
If you're using MySQL, then the configuration file to edit is /etc/mysql/mysql.conf.d/mysqld.cnf.
Now, edit the required configuration file depending on whether you're using MySQL/MariaDB equally follows:
MariaDB:
$ sudo nano /etc/mysql/mariadb.conf.d/ fifty-server.cnf
MySQL:
$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Now, detect the line as marked in the screenshot below.
Change the datadir to /db every bit shown in the screenshot below. So save the file past pressing <Ctrl> + x followed past y and <Enter>.
Now, kickoff the MySQL/MariaBD service with the following command:
MariaDB:
$ sudo systemctl start mariadb
MySQL:
$ sudo systemctl start mysql
Testing MySQL/MariaDB:
At present, try to connect to the MySQL/MariaDB server as follows:
Then, type in the password of the MySQL/MariaDB server and press <Enter>.
Y'all should be logged in to the MySQL/MariaDB shell as root database user. It's an indication that information technology works.
Just, just to be sure, blazon in the following query to observe which directory MySQL/MariaDB is currently using as the data directory.
Every bit you lot can come across, the current information directory is /db but as I configured.
So, that's how you change the MySQL/MariaDB information directory on Ubuntu. Cheers for reading this article.
Source: https://linuxhint.com/change_mysql_data_directory_ubuntu/
Posted by: losoyawhavuld.blogspot.com
0 Response to "How To Find Mysql Installation Path In Linux"
Post a Comment