1 / 9

How to Change Default MySQL Data Directory Linux

Sometimes you may need to change default MySQL directory. Here are the steps to change default data directory in MySQL.<br><br>Visit https://fedingo.com/how-to-change-default-mysql-data-directory-in-linux/

Download Presentation

How to Change Default MySQL Data Directory Linux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Change Default MySQL Data Directory in Linux

  2. Create New Directory We will assume that our MySQL data will be moved to /home/ubuntu/mysql-data. So we will create a new directory for this purpose, using the following commands. We need to ensure that the owner of this directory is mysql:mysql, the default user of MySQL database. # mkdir /home/ubuntu/mysql-data # chown -R mysql:mysql /home/ubuntu/mysql-data

  3. Identify Current MySQL Directory The default data directory of MySQL is located at /var/lib/mysql, it is better to check it using the following MySQL query. # mysql -u root -p -e "SELECT @@datadir;"

  4. Copy MySQL Data Directory (½) You need to stop your MySQL service before you copy its data directory. Run the following commands to stop MySQL server. ------------- On SystemD ------------- # systemctl stop mariadb # systemctl is-active mariadb ------------- On SysVInit ------------- # service mysqld stop # service mysqld status OR # service mysql stop # service mysql status

  5. Copy MySQL Data Directory (2/2) Run the following command to copy MySQL data directory to new location. # cp -R -p /var/lib/mysql/* /home/ubuntu/mysql-data

  6. Update MySQL Configuration Run the following command to open it. # vi /etc/my.cnf OR # vi /etc/mysql/my.cnf Under [mysqld]: datadir=/home/ubuntu/mysql-data socket=/home/ubuntu/mysql-data/mysql.sock Under [client]: port=3306 socket=/home/ubuntu/mysql-data/mysql.sock

  7. Set SELinux Security Context (For RHEL/CentOS) If you are running RHEL/CentOS system, then add SELinux security context to /home/ubuntu/mysql-data before restarting MySQL server. # semanage fcontext -a -t mysqld_db_t "/home/ubuntu/mysql-data(/.*)?" # restorecon -R /mnt/mysql-data

  8. Restart MySQL Server ------------- On SystemD ------------- # systemctl stop mariadb # systemctl is-active mariadb ------------- On SysVInit ------------- # service mysqld stop # service mysqld status OR # service mysql stop # service mysql status

  9. Thank You Visit for details https://fedingo.com/how-to-change-default-mysql-data-directory-in-linux/

More Related