How to detect deadlocks in Mysql / innodb?

334

Solution 1

http://dev.mysql.com/doc/refman/5.0/en/innodb-error-codes.html

1213 (ER_LOCK_DEADLOCK)

Transaction deadlock. You should rerun the transaction.

Solution 2

"SHOW ENGINE INNODB STATUS" from the MySQL Command line client (not a query browser) will give you info on deadlocks.

Deadlocks can also be caused by uncommitted transactions (usually program bugs) and the person who is running the uncommitted transaction will not see the problem as they will be working fine (through their data will not be committed).

Solution 3

Try MaatKit. It has a deadlock logger.

Solution 4

Try using MONyog. Enable MONyog's "Deadlock Monitoring" option to trace the deadlocks reported by INNODB STATUS. MONyog will send an alert to the user when a new deadlock occur. enter image description here

Solution 5

If you are on a mac:

$ brew install percona-toolkit

$ pt-deadlock-logger -uroot --ask-pass localhost

Share:
334
kalculated
Author by

kalculated

Updated on March 29, 2020

Comments

  • kalculated
    kalculated about 4 years

    I am trying to allow a user to select an image from gallery, then pass the image to the next screen as a parameter where they can finish their post (Similar to instagram create flow).

    Using expo image picker, the button can be clicked which opens the gallery, and allows the user to select an image, and the gallery closes. This is done using this code:

    async openImagePickerAsync() {
        let permissionResult = await ImagePicker.requestCameraRollPermissionsAsync();
    
        if (permissionResult.granted === false) {
          alert("Permission to access camera roll is required!");
          return;
        }
    
        let pickerResult = await ImagePicker.launchImageLibraryAsync()
    
        console.log(pickerResult.uri)
        
        if (pickerResult.cancelled === true) {
            return;
        }
    
        this.setPicked(pickerResult);
    };
    

    The console logs the uri, everything is great. The picture is selected. The problem begins in the this.setPicked function call, where I am simply confirming a picture was selected and setting the state:

    setPicked = (pickerResult) => {
        console.log("called setPicked")
    
        if (pickerResult !== null) {
            console.log("pickerResult not null")
            this.setState({
                image: pickerResult.uri
            }).bind(this)
            console.log(pickerResult.uri)
            console.log(this.state.image)
         }
         else {
            console.log("pickerResult is null")
             return;
         }
    }
    

    None of the print statements are printing, and I get this warning in the console:

    [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'this.setPicked')]
    

    Any idea what is going on? Thanks

  • Admin
    Admin about 15 years
    Thank you! That's what I was looking for.
  • Mei
    Mei over 12 years
    Maatkit has been absorbed into the Percona Toolkit recently. The tool is called pt-deadlock-logger and was formerly mk-deadlock-logger.
  • Farid Movsumov
    Farid Movsumov about 8 years
    @S.Lott link is broken
  • OZZIE
    OZZIE over 6 years
    @S.Lott google led me here.... kind of weird place to say such things ^^ when this is a place to gather such information
  • OZZIE
    OZZIE over 5 years
    there is a lot of output.. can I grep for something to detect it?
  • Guruparan Giritharan
    Guruparan Giritharan over 3 years
    Well you need to bind this or use an arrow function to get access to the context, refer this freecodecamp.org/news/…