Skip to content

Instantly share code, notes, and snippets.

@thomasbnt
Forked from angristan/mysql-cheatsheet.md
Last active October 27, 2025 10:51
Show Gist options
  • Select an option

  • Save thomasbnt/f02b6d3fea2c9efc76fd0bed52ce5202 to your computer and use it in GitHub Desktop.

Select an option

Save thomasbnt/f02b6d3fea2c9efc76fd0bed52ce5202 to your computer and use it in GitHub Desktop.

Revisions

  1. thomasbnt revised this gist Sep 16, 2022. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,20 @@ CREATE DATABASE database;
    DROP DATABASE database;
    ```

    ## Manage tables

    ### Create table

    ```sql
    CREATE TABLE table_name;
    ```

    ### Delete table

    ```sql
    DROP TABLE table_name;
    ```

    ## Manage users

    ### Create user
  2. thomasbnt revised this gist Jan 27, 2022. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -106,4 +106,27 @@ if (!empty($dbname)) {
    + $cfg['Servers'][$i]['AllowRoot'] = false;
    }
    ```
    ____
    ## Allow remote connection
    ```bash
    nano /etc/mysql/my.cnf
    ```
    Or other files who MariaDB/MySQL is registered.
    ```diff
    - bind-address = 127.0.0.1
    + bind-address = 0.0.0.0
    ```
    After that, restart the service.
    ```bash
    systemctl restart mariadb
    ```
    You can verify if the process listening to the good IP and port with **netstat** :
    ```bash
    netstat -ant | grep 3306
    ```
  3. thomasbnt revised this gist Jan 16, 2022. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -90,4 +90,20 @@ SHOW GRANTS username;
    ```sql
    FLUSH PRIVILEGES;
    ```
    _____
    ## Disable root login on Phpmyadmin
    Edit `/etc/phpmyadmin/config.inc.php`
    ```diff
    if (!empty($dbname)) {
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    + $cfg['Servers'][$i]['AllowRoot'] = false;
    }
    ```
  4. thomasbnt revised this gist Sep 10, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,8 @@ CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    ### Edit a password for a user

    ```sql
    ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
    ALTER USER 'username'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
    FLUSH PRIVILEGES;
    ```

    ### Delete user
  5. thomasbnt revised this gist Sep 10, 2020. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,12 @@ DROP DATABASE database;
    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    ```

    ### Edit a password for a user

    ```sql
    ALTER USER 'user-name'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
    ```

    ### Delete user

    ```sql
  6. thomasbnt revised this gist May 8, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,10 @@ select host, user, password from mysql.user;
    ```sql
    mysqladmin -u root -p password [NewPassword]
    ```
    or
    ```sql
    sudo mysqladmin -u root password -p
    ```

    ## Permissions

  7. thomasbnt revised this gist Dec 4, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,12 @@ CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    ```sql
    DROP USER ‘username’@‘localhost’;
    ```

    ### Show users

    ```sql
    select host, user, password from mysql.user;
    ```
    ### Edit user password

    ```sql
  8. thomasbnt revised this gist Sep 10, 2019. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ DROP USER ‘username’@‘localhost’;
    ```
    ### Edit user password

    ```bash
    ```sql
    mysqladmin -u root -p password [NewPassword]
    ```

    @@ -45,32 +45,32 @@ DROP USER ‘username’@‘localhost’;

    ### Grant permissions

    ```bash
    ```sql
    GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost';
    ```

    ```bash
    ```sql
    GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;
    ```
    ```bash
    ```sql
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
    ```
    ### Revoke permissions
    ```bash
    ```sql
    REVOKE type_of_permission ON database_name.table_name FROM ‘username’@‘localhost’;
    ```
    ### Show permissions
    ```bash
    ```sql
    SHOW GRANTS username;
    ```
    ## Flush privileges
    ```bash
    ```sql
    FLUSH PRIVILEGES;
    ```
  9. thomasbnt revised this gist Sep 10, 2019. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -45,32 +45,32 @@ DROP USER ‘username’@‘localhost’;

    ### Grant permissions

    ```sql
    ```bash
    GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost';
    ```

    ```sql
    ```bash
    GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;
    ```
    ```sql
    ```bash
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
    ```
    ### Revoke permissions
    ```sql
    ```bash
    REVOKE type_of_permission ON database_name.table_name FROM ‘username’@‘localhost’;
    ```
    ### Show permissions
    ```sql
    ```bash
    SHOW GRANTS username;
    ```
    ## Flush privileges
    ```sql
    ```bash
    FLUSH PRIVILEGES;
    ```
  10. Thomas Bnt revised this gist May 11, 2019. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -53,6 +53,10 @@ GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost';
    GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;
    ```
    ```sql
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
    ```
    ### Revoke permissions
    ```sql
  11. Thomas Bnt revised this gist Jan 30, 2019. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,11 @@ CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    ```sql
    DROP USER ‘username’@‘localhost’;
    ```
    ### Edit user password

    ```bash
    mysqladmin -u root -p password [NewPassword]
    ```

    ## Permissions

  12. @angristan angristan revised this gist Feb 12, 2018. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -2,26 +2,26 @@

    ### Create database

    ```
    ```sql
    CREATE DATABASE database;
    ```
    ### Delete database

    ```
    ```sql
    DROP DATABASE database;
    ```

    ## Manage users

    ### Create user

    ```
    ```sql
    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    ```

    ### Delete user

    ```
    ```sql
    DROP USER ‘username’@‘localhost’;
    ```

    @@ -40,7 +40,7 @@ DROP USER ‘username’@‘localhost’;

    ### Grant permissions

    ```
    ```sql
    GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost';
    ```

    @@ -50,18 +50,18 @@ GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhos
    ### Revoke permissions
    ```
    ```sql
    REVOKE type_of_permission ON database_name.table_name FROM ‘username’@‘localhost’;
    ```
    ### Show permissions
    ```
    ```sql
    SHOW GRANTS username;
    ```
    ## Flush privileges
    ```
    ```sql
    FLUSH PRIVILEGES;
    ```
  13. @angristan angristan created this gist Feb 12, 2018.
    67 changes: 67 additions & 0 deletions mysql-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    ## Manage databases

    ### Create database

    ```
    CREATE DATABASE database;
    ```
    ### Delete database

    ```
    DROP DATABASE database;
    ```

    ## Manage users

    ### Create user

    ```
    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    ```

    ### Delete user

    ```
    DROP USER ‘username’@‘localhost’;
    ```

    ## Permissions

    ### Types of permissions

    * ALL PRIVILEGES
    * CREATE
    * DROP
    * DELETE
    * INSERT
    * SELECT
    * UPDATE
    * GRANT OPTION

    ### Grant permissions

    ```
    GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost';
    ```

    ```sql
    GRANT type_of_permission ON database_name.table_name TO ‘username’@'localhost’;
    ```
    ### Revoke permissions
    ```
    REVOKE type_of_permission ON database_name.table_name FROM ‘username’@‘localhost’;
    ```
    ### Show permissions
    ```
    SHOW GRANTS username;
    ```
    ## Flush privileges
    ```
    FLUSH PRIVILEGES;
    ```