8/16/2023 0 Comments Mysql database file location linux![]() ![]() In this example, “thegeekstuff” is the MySQL database under /var/lib/mysql directory.Īs you see here, mysqld_db_t is the SELinux context type. Before moving the directory, the following was the SELinux context on my MySQL database. Use ls -Z command to view the SELinux context. If you have a tmpdir parameter already defined in your my.cnf file, change the directory for that parameter also: tmpdir=/data/var/lib/mysqlĪfter changing the datadir and socket in the my.cnf file, if MySQL doesn’t start, or fails with a permission denied error message, then you need to set the SELinux (or AppArmor) as explained in the following sections. # vi /etc/my.cnfįinally, restart the MySQL database. In the /etc/my.cnf file, you need to modify both datadir and socket parameter and point them to the new directory as shown below. If not, you might get this error message: MySQL error: 1017Can’t find file: (errno: 13) chown -R mysql:mysql /data But, when you move, the appropriate SELinux context for MySQL are kept in tact and you don’t have to worry about changing it.Īlso, if you’ve copied the directory (instead of move), make sure you change the ownership appropriately. When you perform copy, the SELinux context will be lost, and you have to manually set those later (as explained below). If possible, try to use the move command to move the directory over (instead of copy).But, In this particular instance, I prefer the above simple moving the directory without symbolic link to avoid confusion. You can also move mysql directory to /data/var/lib/ directory, and create a symbolic link from /var/lib pointing to /data/var/lib.So, I’ll be moving the MySQL database from / partition to /data partition.Ĭreate the following directory and move the mysql data from /var/lib to /data/var/lib as shown below. But, I have /data partition on /dev/sdb1 disk which has lot of space. In this example, my root partition is /dev/sda1, which doesn’t have much space for the default /var/lib/mysql directory. Move MySQL Data Directory to Different Partition Or, if you prefer, you can use mysqldump to take a MySQL DB backup. Copy this mysql directory to a different location for backup. Take a Backup of Current MySQLīefore you do anything, stop the MySQL database and take a cold backup of your database.īy default MySQL will database will be under /var/lib/mysql directory. This tutorial explains the details on how to perform the above three steps to move your MySQL data to a different directory. ![]() On Ubuntu or Debian, modify the AppArmor settings. Update security settings to reflect the directory change: On CentOS or RedHat, modify SELinux settings.Modify the my.cnf file with the new directory location.Move MySQL database files from /var/lib/mysql to a different partition.To change the MySQL directory, on a high level, you have to perform the following three steps: In that case, you may want to move your MySQL database from root partition to a different partition. But on production, for a larger database, you might not have enough space under root partition. This might be Ok if you are running a small database that doesn’t take much space. By default MySQL database will be created under /var/lib/mysql directory. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |