无法使用用户root连接到localhost:3306上的mysql

yfwxisqw  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(430)

我已经安装了mysql服务器和mysql工作台。我需要使用workbench接口连接到mysql。我以前在windows中很容易做到这一点,因为服务器的安装也是在图形用户界面中进行的。
但现在我在ubuntu18机器上工作。当我尝试在进入 root 密码我得到这个错误:
我执行此命令以确保密码正确:

mysql> UPDATE mysql.user set authentication_string = PASSWORD('mypass') where user = 'root' and host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit()

然后,当我尝试此操作并输入密码时,再次出现错误:

x@x-VirtualBox:~$ mysql -u root -p -h > localhost -P 3306
Enter password: 
ERROR 2005 (HY000): Unknown MySQL server host '-P' (2)

谁能告诉我怎么了吗?如何建立数据库连接?
编辑:服务肯定正在运行。以下是测试:

x@x-VirtualBox:~$ service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Sat 2018-07-28 20:54:14 WIB; 6min ago
  Process: 12790 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/m
  Process: 12779 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exi
 Main PID: 12792 (mysqld)
    Tasks: 28 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─12792 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pi

Jul 28 20:54:13 e-VirtualBox systemd[1]: Starting MySQL Community Server...
Jul 28 20:54:14 e-VirtualBox systemd[1]: Started MySQL Community Server.


编辑2:使用命令行,我输入根密码,它工作。但是工作台不接受它。

sudo mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.22-0ubuntu18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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>
mkshixfv

mkshixfv1#

你的 mysql.user 表中有多个根用户条目,根据您的连接方式(例如,通过本地unix域套接字或tcp端口)使用不同的条目。看起来您更改了其中一个条目的密码,但没有更改其他条目的密码。
您可以选择:
更改中所有根用户条目的密码 mysql.user
将工作台中的“connection method”(如您的屏幕截图所示)从“standard”更改为“local socket”,这样它将使用与您通过命令行登录时相同的密码

相关问题