L3 Info : SGBD
 
◃  Ch. 15 Administration des SGBD  ▹
 

Administration MySQL

  • Compte administrateur : root (ou un autre utilisateur auquel on a attribué les droits)
  • L'administration se fait dans une BD particulière nommée mysql
  • Les tables disponibles sont les suivantes :
    SHOW TABLES;
    +------------------------------------------------------+
    | Tables_in_mysql                                      |
    +------------------------------------------------------+
    | columns_priv                                         |
    | component                                            |
    | db                                                   |
    | default_roles                                        |
    | engine_cost                                          |
    | func                                                 |
    | general_log                                          |
    | global_grants                                        |
    | gtid_executed                                        |
    | help_category                                        |
    | help_keyword                                         |
    | help_relation                                        |
    | help_topic                                           |
    | innodb_index_stats                                   |
    | innodb_table_stats                                   |
    | password_history                                     |
    | plugin                                               |
    | procs_priv                                           |
    | proxies_priv                                         |
    | replication_asynchronous_connection_failover         |
    | replication_asynchronous_connection_failover_managed |
    | replication_group_configuration_version              |
    | replication_group_member_actions                     |
    | role_edges                                           |
    | server_cost                                          |
    | servers                                              |
    | slave_master_info                                    |
    | slave_relay_log_info                                 |
    | slave_worker_info                                    |
    | slow_log                                             |
    | tables_priv                                          |
    | time_zone                                            |
    | time_zone_leap_second                                |
    | time_zone_name                                       |
    | time_zone_transition                                 |
    | time_zone_transition_type                            |
    | user                                                 |
    +------------------------------------------------------+
    37 rows in set (0,00 sec)
  • Le table user inventories les utilisateurs référencés et leurs droits
    DESCRIBE user;
    +--------------------------+-----------------------------------+------+-----+-----------------------+-------+
    | Field                    | Type                              | Null | Key | Default               | Extra |
    +--------------------------+-----------------------------------+------+-----+-----------------------+-------+
    | Host                     | char(255)                         | NO   | PRI |                       |       |
    | User                     | char(32)                          | NO   | PRI |                       |       |
    | Select_priv              | enum('N','Y')                     | NO   |     | N                     |       |
    | Insert_priv              | enum('N','Y')                     | NO   |     | N                     |       |
    | Update_priv              | enum('N','Y')                     | NO   |     | N                     |       |
    | Delete_priv              | enum('N','Y')                     | NO   |     | N                     |       |
    | Create_priv              | enum('N','Y')                     | NO   |     | N                     |       |
    | Drop_priv                | enum('N','Y')                     | NO   |     | N                     |       |
    | Reload_priv              | enum('N','Y')                     | NO   |     | N                     |       |
    | Shutdown_priv            | enum('N','Y')                     | NO   |     | N                     |       |
    | Process_priv             | enum('N','Y')                     | NO   |     | N                     |       |
    | File_priv                | enum('N','Y')                     | NO   |     | N                     |       |
    | Grant_priv               | enum('N','Y')                     | NO   |     | N                     |       |
    | References_priv          | enum('N','Y')                     | NO   |     | N                     |       |
    | Index_priv               | enum('N','Y')                     | NO   |     | N                     |       |
    | Alter_priv               | enum('N','Y')                     | NO   |     | N                     |       |
    | Show_db_priv             | enum('N','Y')                     | NO   |     | N                     |       |
    | Super_priv               | enum('N','Y')                     | NO   |     | N                     |       |
    | Create_tmp_table_priv    | enum('N','Y')                     | NO   |     | N                     |       |
    | Lock_tables_priv         | enum('N','Y')                     | NO   |     | N                     |       |
    | Execute_priv             | enum('N','Y')                     | NO   |     | N                     |       |
    | Repl_slave_priv          | enum('N','Y')                     | NO   |     | N                     |       |
    | Repl_client_priv         | enum('N','Y')                     | NO   |     | N                     |       |
    | Create_view_priv         | enum('N','Y')                     | NO   |     | N                     |       |
    | Show_view_priv           | enum('N','Y')                     | NO   |     | N                     |       |
    | Create_routine_priv      | enum('N','Y')                     | NO   |     | N                     |       |
    | Alter_routine_priv       | enum('N','Y')                     | NO   |     | N                     |       |
    | Create_user_priv         | enum('N','Y')                     | NO   |     | N                     |       |
    | Event_priv               | enum('N','Y')                     | NO   |     | N                     |       |
    | Trigger_priv             | enum('N','Y')                     | NO   |     | N                     |       |
    | Create_tablespace_priv   | enum('N','Y')                     | NO   |     | N                     |       |
    | ssl_type                 | enum('','ANY','X509','SPECIFIED') | NO   |     |                       |       |
    | ssl_cipher               | blob                              | NO   |     | NULL                  |       |
    | x509_issuer              | blob                              | NO   |     | NULL                  |       |
    | x509_subject             | blob                              | NO   |     | NULL                  |       |
    | max_questions            | int unsigned                      | NO   |     | 0                     |       |
    | max_updates              | int unsigned                      | NO   |     | 0                     |       |
    | max_connections          | int unsigned                      | NO   |     | 0                     |       |
    | max_user_connections     | int unsigned                      | NO   |     | 0                     |       |
    | plugin                   | char(64)                          | NO   |     | caching_sha2_password |       |
    | authentication_string    | text                              | YES  |     | NULL                  |       |
    | password_expired         | enum('N','Y')                     | NO   |     | N                     |       |
    | password_last_changed    | timestamp                         | YES  |     | NULL                  |       |
    | password_lifetime        | smallint unsigned                 | YES  |     | NULL                  |       |
    | account_locked           | enum('N','Y')                     | NO   |     | N                     |       |
    | Create_role_priv         | enum('N','Y')                     | NO   |     | N                     |       |
    | Drop_role_priv           | enum('N','Y')                     | NO   |     | N                     |       |
    | Password_reuse_history   | smallint unsigned                 | YES  |     | NULL                  |       |
    | Password_reuse_time      | smallint unsigned                 | YES  |     | NULL                  |       |
    | Password_require_current | enum('N','Y')                     | YES  |     | NULL                  |       |
    | User_attributes          | json                              | YES  |     | NULL                  |       |
    +--------------------------+-----------------------------------+------+-----+-----------------------+-------+
    51 rows in set (0,00 sec)
  • La table db détaille les informations sur les bases de données disponibles :
    DESCRIBE db;
    +-----------------------+---------------+------+-----+---------+-------+
    | Field                 | Type          | Null | Key | Default | Extra |
    +-----------------------+---------------+------+-----+---------+-------+
    | Host                  | char(255)     | NO   | PRI |         |       |
    | Db                    | char(64)      | NO   | PRI |         |       |
    | User                  | char(32)      | NO   | PRI |         |       |
    | Select_priv           | enum('N','Y') | NO   |     | N       |       |
    | Insert_priv           | enum('N','Y') | NO   |     | N       |       |
    | Update_priv           | enum('N','Y') | NO   |     | N       |       |
    | Delete_priv           | enum('N','Y') | NO   |     | N       |       |
    | Create_priv           | enum('N','Y') | NO   |     | N       |       |
    | Drop_priv             | enum('N','Y') | NO   |     | N       |       |
    | Grant_priv            | enum('N','Y') | NO   |     | N       |       |
    | References_priv       | enum('N','Y') | NO   |     | N       |       |
    | Index_priv            | enum('N','Y') | NO   |     | N       |       |
    | Alter_priv            | enum('N','Y') | NO   |     | N       |       |
    | Create_tmp_table_priv | enum('N','Y') | NO   |     | N       |       |
    | Lock_tables_priv      | enum('N','Y') | NO   |     | N       |       |
    | Create_view_priv      | enum('N','Y') | NO   |     | N       |       |
    | Show_view_priv        | enum('N','Y') | NO   |     | N       |       |
    | Create_routine_priv   | enum('N','Y') | NO   |     | N       |       |
    | Alter_routine_priv    | enum('N','Y') | NO   |     | N       |       |
    | Execute_priv          | enum('N','Y') | NO   |     | N       |       |
    | Event_priv            | enum('N','Y') | NO   |     | N       |       |
    | Trigger_priv          | enum('N','Y') | NO   |     | N       |       |
    +-----------------------+---------------+------+-----+---------+-------+
    22 rows in set (0,00 sec)
  • Exemple de contenu de la table user :
    SELECT user, host FROM user ORDER BY user;
    +------------------+-----------+
    | user             | host      |
    +------------------+-----------+
    | debian-sys-maint | localhost |
    | dominique        | localhost |
    | lambda           | localhost |
    | mysql.infoschema | localhost |
    | mysql.session    | localhost |
    | mysql.sys        | localhost |
    | root             | localhost |
    +------------------+-----------+
    9 rows in set (0,00 sec)
  • Configuration de l'accès de lambda via la classe d'adresse 172.16.0.0
    • Nécessite de cloner l'utilisateur lambda avec la nouvelle connexion souhaitée
    • Autoriser la connexion depuis n'importe quelle adresse ('lambda'@'%') n'est pas recommandé !
    • Possibilité de faire la même chose avec un INSERT dans la table user
    • Possibilité d'avoir un mot de passe différent selon le mode de connexion
      CREATE USER 'lambda'@'172.16.%' IDENTIFIED BY 'lambdapasswordBIS';
      Query OK, 0 rows affected (0,02 sec)
  • Nouvel état de la table user :
    SELECT user, host FROM user ORDER BY user;
    +------------------+-----------+
    | user             | host      |
    +------------------+-----------+
    | debian-sys-maint | localhost |
    | dominique        | localhost |
    | lambda           | 172.16.%  |
    | lambda           | localhost |
    | mysql.infoschema | localhost |
    | mysql.session    | localhost |
    | mysql.sys        | localhost |
    | root             | localhost |
    +------------------+-----------+
    9 rows in set (0,00 sec)
  • Mais aucun privilège pour lambda via ce nouveau mode d'accès (ici seul le select est présenté):
    SELECT user, host, db, select_priv FROM db;
    +---------------+-----------+--------------------+-------------+
    | user          | host      | db                 | select_priv |
    +---------------+-----------+--------------------+-------------+
    | dominique     | localhost | dominique          | Y           |
    | lambda        | localhost | lambdaDB           | Y           |
    | mysql.session | localhost | performance_schema | Y           |
    | mysql.sys     | localhost | sys                | N           |
    +---------------+-----------+--------------------+-------------+
    4 rows in set (0,00 sec)
  • Nécessite un nouveau GRANT (les privilèges peuvent donc être différents):
    GRANT ALL ON lambda.* TO 'lambda'@'172.16.%';
    Query OK, 0 rows affected (0,01 sec)