Several improvements to the ATLAS triggers used to identify jets containing b-hadrons (b-jets) were implemented for data-taking during Run 2 of the Large Hadron Collider from 2016 to 2018. These changes include reconfiguring the b-jet trigger software to improve primary-vertex finding and allow more stable running in conditions with high pile-up, and the implementation of the functionality needed to run sophisticated taggers used by the offline reconstruction in an online environment. These improvements yielded an order of magnitude better light-flavour jet rejection for the same b-jet identification efficiency compared to the performance in Run 1 (2011-2012). The efficiency to identify b-jets in the trigger, and the conditional efficiency for b-jets that satisfy offline b-tagging requirements to pass the trigger are also measured. Correction factors are derived to calibrate the b-tagging efficiency in simulation to match that observed in data. The associated systematic uncertainties are substantially smaller than in previous measurements. In addition, b-jet triggers were operated for the first time during heavy-ion data-taking, using dedicated triggers that were developed to identify semileptonic b-hadron decays by selecting events with geometrically overlapping muons and jets.