Useful MySQL commands

  • Show database sizes
    SELECT table_schema AS DB, SUM(index_length + data_length)/(1024 * 1024) AS "Size (MB)" FROM information_schema.tables GROUP BY table_schema;
    
  • Common privileges for web application DB user:
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON databasename.* TO 'userid'@'host' IDENTIFIED BY 'password';
  • Export grants in an importable format:
    mysql -B -e 'SELECT DISTINCT CONCAT('\''show grants for `'\'', user, '\''`@`'\'', host, '\''`;'\'') AS query FROM mysql.user;' | grep -v query | mysql

-- AvishaiIshShalom - 21 Sep 2010
Topic revision: r2 - 14 Apr 2011 - 17:44:02 - AvishaiIshShalom
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback