bsd:bsdnmy
Table des matières
Mysql
MySQL
Installation du serveur mariadb-server
pkg_add -v mariadb-server-10.3.18v1 The following new rcscripts were installed: /etc/rc.d/mysqld See rcctl(8) for details. Look in /usr/local/share/doc/pkg-readmes for extra documentation.
Installation des bases de données nécessaires au fonctionnement
/usr/local/bin/mysql_install_db Installing MariaDB/MySQL system tables in '/var/mysql' ... OK PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: '/usr/local/bin/mysqladmin' -u root password 'new-password' '/usr/local/bin/mysqladmin' -u root -h obsd-1.home.lan password 'new-password' Alternatively you can run: '/usr/local/bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: /etc/rc.d/mysqld start Please report any problems at http://mariadb.org/jira The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/
- Activation et démarrage du service mysqld
rcctl enable mysqld rcctl start mysqld mysqld(ok)
Configuration du serveur
/usr/local/bin/mysql_secure_installation
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't set the root password yet, the password will be blank,
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] Y
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. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- 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] y
... 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!
Test du service mysqld
mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.3.18-MariaDB OpenBSD port: mariadb-server-10.3.18v1 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.002 sec) MariaDB [(none)]>
Configuration de MySQL
- changer le nom par défaut de l’administrateur root en
MariaDB [(NONE)]> UPDATE mysql.user SET USER = 'panoramix', Password = PASSWORD('123456') WHERE USER='root'; Query OK, 3 ROWS affected (0.158 sec) ROWS matched: 3 Changed: 3 Warnings: 0 MariaDB [(NONE)]> FLUSH PRIVILEGES; Query OK, 0 ROWS affected (0.010 sec) MariaDB [(NONE)]> exit Bye
- ajout des privilèges sur l’entièreté du système pour panoramix
MariaDB [(NONE)]> GRANT ALL PRIVILEGES ON *.* TO 'panoramix'@'192.168.1.0/255.255.255.0' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 ROWS affected (0.033 sec) MariaDB [(NONE)]> FLUSH PRIVILEGES; Query OK, 0 ROWS affected (0.001 sec) MariaDB [(NONE)]> exit Bye
- création utilisateur mysql asterix pour accéder à database wikinuxbsd, connexion localhost
MariaDB [(NONE)]> GRANT SELECT, INSERT, UPDATE, DELETE ON wikinuxbsd.* TO 'asterix'@'localhost' IDENTIFIED BY '123456'; Query OK, 0 ROWS affected (0.010 sec) MariaDB [(NONE)]> FLUSH PRIVILEGES; Query OK, 0 ROWS affected (0.001 sec)
- afficher les privilèges de l'utilisateur asterix
MariaDB [(NONE)]> SHOW GRANTS FOR 'asterix'@'localhost'; +----------------------------------------------------------------------------------------------------------------+ | Grants FOR asterix@localhost | +----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'asterix'@'localhost' IDENTIFIED BY PASSWORD '*DC61CFCC9D17AF95840EC5D8797B7220810374DF' | | GRANT SELECT, INSERT, UPDATE, DELETE ON `wikinuxbsd`.* TO 'asterix'@'localhost' | +----------------------------------------------------------------------------------------------------------------+ 2 ROWS IN SET (0.005 sec)
MySQL commandes utiles
Lister les bases
SHOW DATABASES;
Autoriser une connexion MySQL depuis une machine autre que localhost
/etc/my.cnf # bind-address = 127.0.0.1 (mettre la ligne en commentaire) rcctl restart mysqld CREATE User 'aiko'@'127.0.0.1' IDENTIFIED BY 'a'; CREATE User 'aiko'@'localhost' IDENTIFIED BY 'a'; GRANT ALL PRIVILEGES ON *.* TO 'aiko'@'localhost' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'aiko'@'127.0.0.1' WITH GRANT OPTION; FLUSH PRIVILEGES; FLUSH HOSTS; SELECT USER(); mysql -u aiko -h 127.0.0.1 -p SELECT USER(); CREATE USER 'conex'@'10.10.10' IDENTIFIED BY 'a'; CREATE USER 'conex'@'*' IDENTIFIED BY 'a'; (ou de n'importe quel réseaux) CREATE database db_conex; GRANT ALL ON db_conex.* TO 'conex'@'10.10.10.10'; GRANT ALL ON db_conex.* TO 'conex'@'*'; (ou de n'importe quel réseaux) FLUSH PRIVILEGES; FLUSH HOSTS; SHOW databases; SELECT USER(); mysql -u conex -p ERROR 1045 (28000): Access denied for user 'conex'@'localhost' (using password: YES)
Connexion depuis une machine distante
mysql -h adresse_ip_de_votre_serveur -u nom_utilisateur -p'mot_de_passe'
MySQL Gestion des utilisateurs
Vérifier la liste des utilisateurs
mysql> SELECT Host,User FROM mysql.user;
Créer un utilisateur
mysql> CREATE USER ‘aiko’@’localhost’;
Créer un utilisateur avec password
mysql> CREATE USER ‘aiko’@’localhost’ IDENTIFIED BY ‘password’;
Renommer un utilisateur
mysql> RENAME USER ‘aiko’@’localhost’ TO ‘btsig’@’localhost’;
Supprimer un utilisateur
mysql> DROP USER ‘aiko’@’localhost’;
Attribuer un mot de passe à un utilisateur
mysql> SET PASSWORD FOR ‘aiko’@’localhost’ = PASSWORD(‘mot_de_passe’);
créez un utilisateur et l'autoriser à réaliser certaines opérations sur la base de données
MySQL Démarrage & Status
Démarrage manuel
mysqld_safe
Se connecter à MySQL
mysql -u root -p
Savoir si le serveur fait un .sock (si il run)
ls /var/run/mysql/mysql.sock
Savoir si le serveur à démarré
mysqladmin -u root -p ping Enter password: mysqld is alive
Arrêter le serveur proprement
mysqladmin -u root -p shutdown (gentil avec le p'tit)
Changer le mot de passe root
/usr/local/bin/mysqladmin -u root password '123456789' (le mot de passe est entre les '')
Ajouter un utilisateur
CREATE USER 'aiko'@'localhost' IDENTIFIED BY '123456';
Opération sur database
Afficher les database
SHOW DATABASES;
Sectionner une database
USE madatabase;
Renommer une database
bsd/bsdnmy.txt · Dernière modification : de 127.0.0.1
