无法使用root用户连接到localhost:3306上的MySQL
我已经安装了mysql服务器和mysql工作台。我需要使用workbench接口连接到mysql。我过去在Windows中很容易做到这一点,因为服务器的安装也是在图形用户界面中进行的 但现在我在Ubuntu18机器上工作。在输入无法使用root用户连接到localhost:3306上的MySQL,mysql,database,ubuntu,database-connection,mysql-workbench,Mysql,Database,Ubuntu,Database Connection,Mysql Workbench,我已经安装了mysql服务器和mysql工作台。我需要使用workbench接口连接到mysql。我过去在Windows中很容易做到这一点,因为服务器的安装也是在图形用户界面中进行的 但现在我在Ubuntu18机器上工作。在输入root密码后尝试测试连接时,出现以下错误: 我执行此命令以确保密码正确: mysql> UPDATE mysql.user set authentication_string = PASSWORD('mypass') where user = 'root' and
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:
我使用命令行输入root密码,它就可以工作了。但是工作台不接受它
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>
您的
mysql.user
表中有多个根用户条目,根据您的连接方式(例如通过本地unix域套接字或tcp端口)使用不同的条目。看起来您更改了其中一个条目的密码,但没有更改其他条目的密码
你的选择是:
- 更改mysql中所有根用户项的密码。用户或
- 将工作台中的“连接方法”(如屏幕截图所示)从“标准”更改为“本地套接字”,这样它将使用与您通过命令行登录时相同的密码