Nous utilisons MySQL pour la base de données.
Sous Ubuntu, l'accès à la base données se fait en tant qu'administrateur avec la commande sudo
sur le compte
richer@zentopia:\$~/dev/symfony/$ sudo mysql -u root -p
> create database mabd;
> create user 'utilisateur'@'localhost' identified by 'motdepasse';
> grant all privileges on mabd.* to 'utilisateur'@'localhost';
> flush privileges;
> exit;
On crée donc un compte de libellé utilisateur et de mot de passe motdepasse doté de tous les privilèges afin de pouvoir insérer, supprimer, modifier des données ou des tables.
En ce qui concerne Symfony il faut modifier le fichier
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
en:
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://utilisateur:motdepasse@127.0.0.1:3306/mabd?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
Veillez à mettre en commentaire la ligne qui donne accès à Postgresql.
Parfois l'installation plante ou alors il y a un conflit avec maria-db, il faut donc réinstaller mysql :
~/dev/symfony/$ sudo apt remove --purge mysql-server mysql-client mysql-common mysql-server-8.0
puis les commandes suivantes :
sudo apt autoremove
sudo apt autoclean
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt update
sudo apt install mysql-server
Enfin, sécuriser l'installation :
richer@zentopia:\$~/dev/symfony/$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: No
Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.
All done!