【问题标题】:How can I connect to a MariaDB (MySQL) instance on localhost?如何连接到本地主机上的 MariaDB (MySQL) 实例?
【发布时间】:2017-01-13 00:05:23
【问题描述】:

我正在使用 MariaDB(而不是 MySQL)安装 FrontAccounting,仅供我个人使用,通过 http://localhost/frontaccounts 上的浏览​​器访问它。但是尝试以root 登录来设置数据库不起作用:无法连接到数据库。用户或密码无效...。在 phpMyAdmin、SQLbuddy、MySQL Workbench 等中尝试以root 登录时会出现类似的错误消息。

(事实上,这个问题也可能出现在 MySQL 中,所以你可以在后面出现 'MariaDB' 的地方替换为 'MySQL'。)

问题是我试图以root 从我的计算机的 IP 地址 (root@MYCOMPUTER) 登录到在“不同”IP 地址 (127.0.0.1, localhost) 需要root@localhost——即使它是同一台计算机!

如何解决这个问题?

【问题讨论】:

标签: mysql linux login connection mariadb


【解决方案1】:

我最终找到的以下答案将允许您在一个 IP 地址创建一个用户以访问另一个地址的 MariaDB (MySQL) 服务器,即使该地址是 127.0.0.1localhost

在终端窗口中,输入:

$ sudo mysql -u root -p -h localhost

输入您的密码:

[sudo] password for YOURUSERNAME: 

输入 MariaDB root 密码,或按 Enter(默认为空密码):

Enter password: 

MariaDB Monitor 欢迎横幅出现...

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 39
Server version: 10.0.28-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

...监视器命令提示符等待您的输入(none 表示您尚未连接到任何数据库):

MariaDB [(none)]> 

localhost 创建一个用户,MariaDB 接受并退出:

MariaDB [(none)]> CREATE USER 'root'@'%';
     -> \q;
Bye
~$

这至少允许您连接,并且是允许其他用户连接的模型。这些最少的指令会留下安全漏洞,因此,在您在 MariaDB 上创建用户、给他们密码(不要忘记root)并授予权限和角色之后,这些漏洞将被关闭。

为提高安全性,请指定用户机器的 IP 地址,例如'root'@'localhost' 而不是 'root'@'%'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-29
    • 2018-06-15
    • 2013-12-24
    • 2020-05-26
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多