# Commandes General

<span style="color: rgb(45, 194, 107);">Poids base de doonnées</span>

```mysql
SELECT sum( data_length + index_length) / 1024 / 1024 "Nom-de-la-base Taille en Mo" FROM information_schema.TABLES WHERE table_schema = "nom-de-base" GROUP BY table_schema;
```

<span style="color: rgb(45, 194, 107);">Read permission</span>

```mysql
GRANTSELECTON DBNAME.TABLE_NAME TO USERNAME 
```

<span style="color: rgb(230, 126, 35);"><span style="color: rgb(45, 194, 107);">liste toutes les BDD</span>  
</span>

```mysql
show databases;
```

<span style="color: rgb(45, 194, 107);">se met sur la BDD qui nous intéresse </span>

```mysql
Use nomdelabdd; 
```

<span style="color: rgb(45, 194, 107);">Suppression de la BDD</span>

```mysql
Drop database nomdelabdd;
```

<span style="color: rgb(45, 194, 107);">Création de la BDD </span>

```mysql
Create database nomdelabdd;
```

<span style="color: rgb(45, 194, 107);">Dans le cas où le compte mysqldump n'a pas les droits de restauration de dump</span>

```mysql
grant all privileges on *.* to mysqldump@localhost;
```

<span style="color: rgb(230, 126, 35);"><span style="color: rgb(45, 194, 107);">Restauration du dump dans la BDD</span></span>

```mysql
mysql -u mysqldump -p "nomdelabdd" < "/production/mysql_dump/nomdelabdd.sql"
```

<span style="color: rgb(45, 194, 107);">Vérification de la bonne restauration du dump</span>

```bash
ls -alsh /production/mysql/nomdelabdd/ 
```

<span style="color: rgb(45, 194, 107);">Pour se connecter</span>

```bash
mysql
```

<span style="color: rgb(45, 194, 107);">Pour avoir la taille de toutes les BDD:</span>

```mysql
SELECT table_schema AS "Database",  ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"  FROM information_schema.TABLES  GROUP BY table_schema;
```

<span style="color: rgb(45, 194, 107);">Pour avoir la taille de toutes les tables d'une BDD:</span>

```mysql
SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "database_name" ORDER BY (data_length + index_length) DESC;
```

<span style="color: rgb(230, 126, 35);"><span style="color: rgb(45, 194, 107);">Reset Mot de passe Mysql:</span>  
</span>

```mysql
ALTER USER 'mysqldump'@'localhost' IDENTIFIED BY 'dump';
```