mysql user grants

-- Grants / privileges list
SELECT * FROM information_schema.user_privileges;
SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user;

-- Grant a user
/*  ALL PRIVILEGES  All privileges
    CREATE          Create databases and tables
    DROP            Drop databases and tables
    DELETE          Delete rows from a specific table
    INSERT          Insert rows into a specific table
    SELECT          Read a database
    UPDATE          Update table rows   */
GRANT SELECT, UPDATE ON db_name.table_name TO 'my_user'@'localhost';
GRANT SELECT ON *.* TO 'my_user'@'localhost';
GRANT ALL PRIVILEGES ON db_name.* TO 'my_user'@'localhost';

--Display user grants
SHOW GRANTS FOR 'my_user'@'localhost';

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source