Get MySQL User Definition

Cool and easy script to get the MySQL users definition for a specific host. This can be altered as you wish. This is useful when you are altering users definition in batch mode

  • Here is an example of it
  • mysql -uuser -ppassw  -s <<< 'SELECT CONCAT("SHOW GRANTS FOR ",user,"@",host,";") FROM mysql.user WHERE host="host.com";'| sed -e "s/FOR /&'/" -e "s/@/'&'"/ -e "s/;/'&/"| mysql -uuser -ppassw -s
    
    --Output will be something like this
    
    GRANT USAGE ON *.* TO 'B_BIB'@'host.com' IDENTIFIED BY PASSWORD '6a07e2bsdfea4fdc9b24'
    GRANT ALL PRIVILEGES ON B_BIB.* TO 'B_BIB'@'host.com'
    GRANT USAGE ON *.* TO 'B_JR7'@'host.com' IDENTIFIED BY PASSWORD '465d77ad74sdfsefs4d651a'
    GRANT ALL PRIVILEGES ON B_JR7.* TO 'B_JR7'@'host.com'