无法使用 DBeaver 连接到 MariaDB

2022-01-15 00:00:00 ubuntu database mariadb mysql dbeaver

我刚刚在 Ubuntu 18.04 上安装了 MariaDB 10.1.29.从命令行我可以使用 sudo 进行连接:

I just installed MariaDB 10.1.29 on Ubuntu 18.04. From the command line I can connect using sudo:

sudo mysql -u root -p

但不是没有 sudo.

But not without sudo.

另外,如果我尝试通过 DBeaver 连接到数据库,我会得到:

Also, if I try to connect to the database through DBeaver, I get:

Could not connect: Access denied for user 'root'@'localhost'

虽然凭据正确.我尝试安装 MySQL 5.7,但我也遇到了完全相同的问题.

While the credentials are correct. I tried installing MySQL 5.7, but I'm experiencing the exact same issue there as well.

我错过了什么?

推荐答案

事实证明,这是 MariaDB 和 MySQL 的预期行为.为了克服这个问题,建议创建一个单独的用户并授予对创建的所有数据库的访问权限.以下是有关如何使用命令行创建数据库并向您选择的用户授予权限的分步指南.

As it turns out, this is expected behaviour for MariaDB and MySQL. To overcome the issue, it is advisable to create a separate user and grant access to all databases created. Here is a step by step guide on how to create databases using the command line and grant permissions to the user of your choice.

$ sudo mysql -u root -p

创建数据库

mysql> CREATE DATABASE `database_name`;

创建用户

mysql> CREATE USER 'user_name' IDENTIFIED BY 'a_secure_password';

授予用户权限

mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'%' WITH GRANT OPTION;

应用更改

mysql> FLUSH PRIVILEGES;

相关文章