Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Access denied for user 'root'@'localhost'

Boa noite pessoal,

Uso o ubuntu 22.04.3 LTS, instalei o mysql, segui os processos da aula, mas qdo vou conetar aparecem essas msgs no log:

..... org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Unable to obtain connection from database: Access denied for user 'root'@'localhost'

.....Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: Access denied for user 'root'@'localhost'

application.properties:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.url=jdbc:mysql://localhost/vollmed_api

spring.datasource.username=root

spring.datasource.password=root

service mysql status

● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2023-09-29 19:04:44 -03; 1h 3min ago Process: 4627 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 4635 (mysqld) Status: "Server is operational" Tasks: 39 (limit: 18858) Memory: 366.6M CPU: 36.333s CGroup: /system.slice/mysql.service └─4635 /usr/sbin/mysqld

no terminal qundo tento acessar: mysql -u root -p

Enter password: ERROR 1698 (28000): Access denied for user 'root'@'localhost'

só acesso assim: sudo mysql -u root -p

Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 8.0.34-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Agradeço a desde já !

1 resposta
solução!

Pessoal,

Consegui achar a solução. Segui esses passos e consegui conectar:

Fonte: https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04

First, connect in sudo mysql

sudo mysql -u root Check your accounts present in your db

SELECT User,Host FROM mysql.user; +------------------+-----------+ | User | Host | +------------------+-----------+ | admin | localhost | | debian-sys-maint | localhost | | magento_user | localhost | | mysql.sys | localhost | | root | localhost | Delete current root@localhost account

mysql> DROP USER 'root'@'localhost'; Query OK, 0 rows affected (0,00 sec) Recreate your user

mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY ''; Query OK, 0 rows affected (0,00 sec) Give permissions to your user (don't forget to flush privileges)

mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION; Query OK, 0 rows affected (0,00 sec)

mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0,01 sec) Exit MySQL and try to reconnect without sudo from your local machine.

Edit: a previous version of the answer post recommended creating a user 'root'@'%'. However, it is more secure to create 'root'@'localhost' so connections can only be made from localhost, and not remotely. Both solutions work equally as well for local development.

I hope this will help someone :)