Changing the Error Log Location

LinuxLinuxBeginner
Practice Now

Introduction

In this project, you will learn how to change the default error log location for the MySQL database server. By the end of this project, you will be able to:

  • Create a dedicated directory for storing MySQL error logs
  • Set the appropriate permissions and ownership for the log directory and file
  • Modify the MySQL configuration files to change the default error log location

👀 Preview

Unfinished

ðŸŽŊ Tasks

In this project, you will learn:

  • How to create a new directory for storing MySQL error logs
  • How to change the user, group, and permissions for the log directory and file
  • How to modify the MySQL configuration files to set the new error log location

🏆 Achievements

After completing this project, you will be able to:

  • Customize the location of the MySQL error logs to a more convenient directory
  • Ensure proper permissions and ownership for the MySQL error log files
  • Confidently navigate and modify MySQL configuration files to suit your needs

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/VersionControlandTextEditorsGroup(["`Version Control and Text Editors`"]) mysql(("`MySQL`")) -.-> mysql/SystemManagementToolsGroup(["`System Management Tools`"]) linux/BasicFileOperationsGroup -.-> linux/chown("`Ownership Changing`") linux/BasicFileOperationsGroup -.-> linux/chmod("`Permission Modifying`") linux/VersionControlandTextEditorsGroup -.-> linux/vim("`Text Editing`") mysql/SystemManagementToolsGroup -.-> mysql/show_variables("`Configuration Overview`") subgraph Lab Skills linux/chown -.-> lab-301294{{"`Changing the Error Log Location`"}} linux/chmod -.-> lab-301294{{"`Changing the Error Log Location`"}} linux/vim -.-> lab-301294{{"`Changing the Error Log Location`"}} mysql/show_variables -.-> lab-301294{{"`Changing the Error Log Location`"}} end

Create the MySQL Log Directory and Set Permissions

In this step, you will create the MySQL log directory and set the appropriate permissions.

  1. Create the mysql directory under the ~/project directory and move the my.log file into this directory.

    mkdir ~/project/mysql
    touch ~/project/mysql/my.log
  2. Change the user, user group, and mode of the ~/project/mysql/my.log file and the ~/project/mysql directory using the sudo command.

    sudo chown mysql:mysql ~/project/mysql/my.log
    sudo chown mysql:mysql ~/project/mysql
    sudo chmod 755 /home/labex

This command sets the owner and group of the my.log file and the mysql directory to mysql:mysql, and sets the permissions on the home directory (/home/labex) to 755 (read, write, and execute for the owner, read and execute for the group and others).

Modify the MySQL Configuration Files

In this step, you will modify the MySQL configuration files to change the default error log location.

  1. Navigate to the /etc/mysql/mariadb.conf.d directory.

    cd /etc/mysql/mariadb.conf.d
  2. Open the 50-server.cnf file using a text editor.

    sudo vim 50-server.cnf
  3. In the [mysqld] section, uncomment the log_error option and set the path to "/home/labex/project/mysql/my.log".

    [mysqld]
    log_error = /home/labex/project/mysql/my.log
    Unfinished
  4. Open the 50-mysqld_safe.cnf file using a text editor.

    sudo vim 50-mysqld_safe.cnf
  5. In the [mysqld_safe] section, comment out the skip_log_error option.

    [mysqld_safe]
    #skip_log_error
    Unfinished

These changes will ensure that the MySQL error logs are written to the my.log file in the ~/project/mysql directory, and that the skip_log_error option is commented out.

Restart the MySQL Service and Verify the Changes

In this step, you will restart the MySQL service and verify that the changes have been applied correctly.

  1. Start the MySQL service.

    sudo service mysql start
  2. Connect to the MySQL command-line interface.

    mysql -uroot
  3. Use the SQL statement to check the value of the log_error variable.

    SHOW VARIABLES LIKE 'log_error';
    MariaDB [(none)]> SHOW VARIABLES LIKE 'log_error';
    +---------------+----------------------------------+
    | Variable_name | Value                            |
    +---------------+----------------------------------+
    | log_error     | /home/labex/project/mysql/my.log |
    +---------------+----------------------------------+
    1 row in set (0.001 sec)

The output should show that the log_error variable is set to the correct path, /home/labex/project/mysql/my.log.

Congratulations! You have successfully changed the MySQL error log location to the my.log file in the ~/project/mysql directory.

âœĻ Check Solution and Practice

Summary

Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.

Other Linux Tutorials you may like