mysql – ExpLinux https://www.explinux.com Explore Linux How to, Tutorials, Unix, Updates, Technology. Fri, 04 Jun 2021 11:30:34 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://www.explinux.com/wp-content/uploads/2023/04/cropped-favicon-32x32-1-32x32.png mysql – ExpLinux https://www.explinux.com 32 32 Mysql resource is unable to start after failover due to permission change on ‘/var/lib/mysql’ directory. https://www.explinux.com/2021/04/mysql-resource-is-unable-to-start-after-failover-due-to-permission-change-on-var-lib-mysql-directory.html https://www.explinux.com/2021/04/mysql-resource-is-unable-to-start-after-failover-due-to-permission-change-on-var-lib-mysql-directory.html#comments Thu, 08 Apr 2021 11:05:00 +0000 Mysql resource is unable to start after failover due to permission change on ‘/var/lib/mysql’ directory. Read More »

]]>
If you are working on a cluster, after a sudden failover you face the issue that Mysql is unable to start.

In this article, we will show you how to solve the issue.

Environment

  • Red Hat Enterprise Linux Server 6 (with the High Availability and Resilient Storage Add Ons)
  • Red Hat Enterprise Linux Server 7
  • Red Hat Enterprise Linux Server 8
  • MySQL

Issue

  • Permission of mount point of MySQL data directory gets changed.
  • Mysql resource is unable to start in the other node after failover from the first node.

    
    Sep  2 16:23:57 node A rgmanager[144383]: [fs] mounting /dev/dm-4 on /var/lib/mysql
    Sep  2 16:23:57 node A kernel: EXT4-fs (dm-4): mounted filesystem with ordered data mode. Opts: 
    Sep  2 16:23:57 node A rgmanager[144527]: [mysql] Checking Existence Of File /var/run/cluster/mysql/mysql:DB_name.pid [mysql:DB_name] > Failed 
    Sep  2 16:23:57 node A rgmanager[144549]: [mysql] Monitoring Service mysql:DB_name > Service Is Not Running 
    Sep  2 16:23:57 node A rgmanager[144571]: [mysql] Starting Service mysql:DB_name
    Sep  2 16:24:27 node A rgmanager[145724]: [mysql] Starting Service mysql:DB_name > Failed - Timeout Error 
    Sep  2 16:24:27 node A rgmanager[4142]: start on mysql "DB_name" returned 1 (generic error)
    

Resolution

  • Change the UID and GID of the MySQL user and keep it the same across all the cluster nodes.
  • Also, check that the UID and GID which you are going to assign for the MySQL user should not be possessed by any other user. If any then kindly change the UID and GID before changing the MySQL credentials.
  • Once after changing the credentials now try to failover the service from one node to another and the service should start without any issue.

Root Cause

  • The User and Group credentials of Mysql are not the same in all the cluster nodes.

    On node A
    # ls -ld /var/lib/mysql/
    drwxr-xr-x 5 495 490 4096 Sep 11 00:21 /var/lib/mysql/
    # grep -i mysql /etc/passwd
    mysql:x:496:491:MySQL server:/var/lib/mysql:/bin/bash

    On node B
    # ls -ld /var/lib/mysql/
    drwxr-xr-x 5 496 491 4096 Sep 11 00:22 /var/lib/mysql/
    # grep -i mysql /etc/passwd
    mysql:x:495:490:MySQL server:/var/lib/mysql:/bin/bash

  • As it can be seen from the above output that  UID and GID of the MySQL user on the first node is 496 and 491 respectively. And the UID and GID of the MySQL user in the second node of the cluster is 495 and 490 respectively.

  • For mysql to access the data from /var/lib/mysql which is the default home directory, permission needs to be mysql:mysql.
    Because of the different UID and GID of the mysql the user on both the nodes, when the cluster relocates the mysql resource from one node to other node it mounts the mysql data on the second node with the same UID and GID of the first node which does not match the mysql credentials on the second node due to which the mysql resource was not able to start on the second node.
Now you have successfully recovered from the issue. Please let us know if this helped you.
]]>
https://www.explinux.com/2021/04/mysql-resource-is-unable-to-start-after-failover-due-to-permission-change-on-var-lib-mysql-directory.html/feed 2
How to reset my MySQL database root password? https://www.explinux.com/2021/01/how-to-reset-my-mysql-database-root-password.html https://www.explinux.com/2021/01/how-to-reset-my-mysql-database-root-password.html#respond Sun, 17 Jan 2021 02:02:00 +0000 How to reset my MySQL database root password? Read More »

]]>
How to reset my MySQL database root password?
This is a very common issue if you are working in a big environment or a system where everything is automated. People always forgot their MySQL password. This article will help you recover your password without any data corruption.

Environment

  • Red Hat Enterprise Linux including:

    • Red Hat Enterprise Linux 3
    • Red Hat Enterprise Linux 4
    • Red Hat Enterprise Linux 5
    • Red Hat Enterprise Linux 6
    • Red Hat Enterprise Linux 7
    • Red Hat Enterprise Linux 8
  • MySQL-server

Issue

 Forgot the MySQL root password. And you want to know how to reset your password. How do I reset the mysql-server password?

# mysql -u root'
Access denied for user 'root'@'localhost' (using password: NO)'

Resolution

To reset the MySQL root password We have to follow the below procedure :

  1. The first Step stop the MySQL service:
    # service mysqld stop
    Stopping MySQL: [ OK ]
  2. Use the below command to start MySQL :

    # /usr/bin/mysqld_safe --skip-grant-tables &

    Note: On RHEL 3, mysqld_safe was called safe_mysqld:

    # /usr/bin/safe_mysqld --skip-grant-tables &

    Note: mysql_safe is a shell script this will only invoke mysqld but additionally traps any forceful terminations of the MySQL server and this will avoid any database corruption. 

  3. Change the password of the root user:

    # mysql -u root mysql
    mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root';
    mysql> FLUSH PRIVILEGES;
    mysql> exit;
  4.   Now Restart mysqld first use mysqladmin to ensure that the service shutdown successfully to avoid any other issue.

    # mysqladmin -p shutdown

  5. Now restart the MySQL service as per normal:

    # service mysqld start 

Root Cause

  • The root password for mysqld was forgotten or lost.
  • You are a new admin and the old admin did not handover passwords.
  • Other team members reset the password and missed it.
  • Use of file to create a new server but MySQL password is not mentioned in doc.
]]>
https://www.explinux.com/2021/01/how-to-reset-my-mysql-database-root-password.html/feed 0