mysql
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| mysql [2018/03/23 11:04] – [Sécurité] simon | mysql [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== MySQL ====== | ||
| - | ===== Installation ===== | ||
| - | <code bash> | ||
| - | root@serveur:/ | ||
| - | </ | ||
| - | |||
| - | ===== Sécurité ===== | ||
| - | Après l' | ||
| - | |||
| - | <code bash> | ||
| - | root@serveur:/ | ||
| - | |||
| - | NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB | ||
| - | SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! | ||
| - | |||
| - | In order to log into MariaDB to secure it, we'll need the current | ||
| - | password for the root user. If you've just installed MariaDB, and | ||
| - | you haven' | ||
| - | so you should just press enter here. | ||
| - | |||
| - | Enter current password for root (enter for none): | ||
| - | OK, successfully used password, moving on... | ||
| - | |||
| - | Setting the root password ensures that nobody can log into the MariaDB | ||
| - | root user without the proper authorisation. | ||
| - | |||
| - | Set root password? [Y/n] | ||
| - | New password: | ||
| - | Re-enter new password: | ||
| - | Password updated successfully! | ||
| - | Reloading privilege tables.. | ||
| - | ... Success! | ||
| - | |||
| - | |||
| - | By default, a MariaDB installation has an anonymous user, allowing anyone | ||
| - | to log into MariaDB without having to have a user account created for | ||
| - | them. This is intended only for testing, and to make the installation | ||
| - | go a bit smoother. | ||
| - | production environment. | ||
| - | |||
| - | Remove anonymous users? [Y/n] | ||
| - | ... Success! | ||
| - | |||
| - | Normally, root should only be allowed to connect from ' | ||
| - | ensures that someone cannot guess at the root password from the network. | ||
| - | |||
| - | Disallow root login remotely? [Y/n] | ||
| - | ... Success! | ||
| - | |||
| - | By default, MariaDB comes with a database named ' | ||
| - | access. | ||
| - | before moving into a production environment. | ||
| - | |||
| - | Remove test database and access to it? [Y/n] | ||
| - | - Dropping test database... | ||
| - | ... Success! | ||
| - | - Removing privileges on test database... | ||
| - | ... Success! | ||
| - | |||
| - | Reloading the privilege tables will ensure that all changes made so far | ||
| - | will take effect immediately. | ||
| - | |||
| - | Reload privilege tables now? [Y/n] | ||
| - | ... Success! | ||
| - | |||
| - | Cleaning up... | ||
| - | |||
| - | All done! If you've completed all of the above steps, your MariaDB | ||
| - | installation should now be secure. | ||
| - | |||
| - | Thanks for using MariaDB! | ||
| - | </ | ||
| - | |||
| - | |||
| - | ===== Quelques exemples ===== | ||
| - | Se connecter : | ||
| - | <code bash> | ||
| - | $ mysql -u root -p | ||
| - | Enter password: | ||
| - | (...) | ||
| - | </ | ||
| - | |||
| - | Voir les base de données existantes : | ||
| - | <code bash> | ||
| - | mysql> SHOW DATABASES; | ||
| - | +--------------------+ | ||
| - | | Database | ||
| - | +--------------------+ | ||
| - | | information_schema | | ||
| - | | mysql | | ||
| - | | (...) | | ||
| - | +--------------------+ | ||
| - | </ | ||
| - | |||
| - | Voir les tables dans une base de données : | ||
| - | <code bash> | ||
| - | mysql> show tables in nextcloud; | ||
| - | +-----------------------------+ | ||
| - | | Tables_in_nextcloud | ||
| - | +-----------------------------+ | ||
| - | | oc_accounts | ||
| - | | oc_activity | ||
| - | | (...) | | ||
| - | +-----------------------------+ | ||
| - | </ | ||
| - | |||
| - | Créer une base de données : | ||
| - | <code bash> | ||
| - | mysql> CREATE DATABASE nom-de-la-db; | ||
| - | Query OK, 1 row affected (0.00 sec) | ||
| - | </ | ||
| - | |||
| - | Créer un nouvel utilisateur pour une base de données : | ||
| - | <code bash> | ||
| - | mysql> CREATE USER ' | ||
| - | Query OK, 0 rows affected (0.00 sec) | ||
| - | </ | ||
| - | |||
| - | Donner les droits à un utilisateur pour une base de données : | ||
| - | <code bash> | ||
| - | mysql> GRANT ALL PRIVILEGES ON [nom_DB].* TO ' | ||
| - | Query OK, 0 rows affected (0.01 sec) | ||
| - | </ | ||
| - | |||
| - | Supprimer une base de données : | ||
| - | <code bash> | ||
| - | mysql> drop database ' | ||
| - | </ | ||
| - | |||
| - | ===== mysqldump ===== | ||
| - | ==== Faire des " | ||
| - | Une seule base de données : | ||
| - | <code bash> | ||
| - | # mysqldump -u root -p database1 > / | ||
| - | </ | ||
| - | |||
| - | Plusieurs bases de données : | ||
| - | <code bash> | ||
| - | # mysqldump -u root -p --databases databaseb1 database2 database3 > / | ||
| - | Enter password: | ||
| - | </ | ||
| - | |||
| - | Vérification : | ||
| - | <code bash> | ||
| - | # grep " Database:" | ||
| - | -- Host: localhost | ||
| - | -- Current Database: `database1` | ||
| - | -- Current Database: `database2` | ||
| - | -- Current Database: `database3` | ||
| - | </ | ||
| - | |||
| - | ==== Restaurer ==== | ||
| - | On peut créer une base de données (pour tester), la sauvegarder et puis la supprimer pour enfin essayer de la restaurer. | ||
| - | |||
| - | Pour supprimer la DB, on utilise " | ||
| - | <code bash> | ||
| - | mysql root@localhost: | ||
| - | </ | ||
| - | |||
| - | Si on essaye de restaurer la base de données, sans la recréer au préalable, on a une erreur disant qu' | ||
| - | <code bash> | ||
| - | mysql root@localhost: | ||
| - | </ | ||
| - | |||
| - | Pour restaurer, on utilise **mysql** (et non mysqldump!!) : | ||
| - | <code bash> | ||
| - | # mysql -u root -p database1 < / | ||
| - | Enter password: | ||
| - | </ | ||
| - | |||
| - | ===== mycli ===== | ||
| - | <code bash> | ||
| - | # apt-get install python3-dev python3-pip | ||
| - | </ | ||
| - | < | ||
| - | <code bash> | ||
| - | Reading package lists... Done | ||
| - | Building dependency tree | ||
| - | Reading state information... Done | ||
| - | The following extra packages will be installed: | ||
| - | libpython3-dev libpython3.4 libpython3.4-dev python3-chardet python3-colorama python3-distlib python3-html5lib python3-requests | ||
| - | python3-setuptools python3-six python3-urllib3 python3-wheel python3.4-dev | ||
| - | (...) | ||
| - | </ | ||
| - | </ | ||
| - | |||
| - | <code bash> | ||
| - | # pip3 install mycli | ||
| - | </ | ||
| - | |||
| - | ===== Sources ===== | ||
| - | * [[https:// | ||
mysql.1521803077.txt.gz · Dernière modification : (modification externe)
