我已经安装了mysql服务器和mysql工作台。我需要使用工作台界面连接到mysql。我以前在Windows中很容易做到这一点,因为服务器安装也是在图形用户界面中。
但是现在我正在Ubuntu 18机器上工作。输入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>
答案 0 :(得分:0)
您的mysql.user
表为root用户提供了多个条目,并且根据您的连接方式(例如,通过本地unix域套接字或tcp端口)使用了不同的条目。看来您已更改了其中一项的密码,但未更改其他项。
您的选择是:
mysql.user
或