简体   繁体   English

无法连接到数据库服务器(mysql workbench)

[英]Cannot connect to Database server (mysql workbench)

Could you help me solve this problem?你能帮我解决这个问题吗?

When I try to click "query database" under database menu in Mysql workbench.当我尝试在 Mysql 工作台中的数据库菜单下单击“查询数据库”时。 it gives me an error:它给了我一个错误:

Cannot Connect to Database Server无法连接到数据库服务器

Your connection attempt failed for user 'root' from your host to server at 127.0.0.1:3306:Can't connect to mysql server on '127.0.0.1'(10061)您的用户“root”从您的主机连接到位于 127.0.0.1:3306 的服务器的尝试失败:无法连接到“127.0.0.1”(10061) 上的 mysql 服务器

Please:请:

  1. Check that mysql is running on server 127.0.0.1检查 mysql 是否在服务器 127.0.0.1 上运行
  2. Check that mysql is running on port 3306 (note: 3306 is the default, but this can be changed)检查 mysql 是否运行在 3306 端口(注意:3306 是默认值,但可以更改)
  3. Check the root has rights to connect to 127.0.0.1 from your address (mysql rights define what clients can connect to the server and from which machines)检查 root 是否有权从您的地址连接到 127.0.0.1(mysql 权限定义哪些客户端可以连接到服务器以及从哪些机器连接)
  4. Make sure you are both providing a password if needed and using the correct password for 127.0.0.1 connecting from the host address you're connecting from确保在需要时提供密码,并使用正确的密码从您要连接的主机地址连接 127.0.0.1

The issue is likely due to socket authentication being enabled for the root user by default when no password is set, during the upgrade to ubuntu 16.04.该问题可能是由于在升级到 ubuntu 16.04 期间未设置密码时默认为 root 用户启用了套接字身份验证。

The solution is to revert back to native password authentication.解决方案是恢复到本机密码身份验证。 You can do this by logging in to MySQL using socket authentication by doing:您可以通过执行以下操作使用套接字身份验证登录 MySQL 来做到这一点:

sudo mysql -u root

Once logged in:登录后:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

which will revert back to the native (old default) password authentication.这将恢复到本机(旧默认)密码身份验证。

Now use password as the password whenever required by MySQL.现在在 MySQL 需要时使用密码作为密码。

尝试从开始菜单搜索框打开services.msc ,尝试手动启动MySQL服务或直接在Run框中写入services.msc

It looks like there are a lot of causes of this error.看起来这个错误有很多原因。

My Cause / Solution我的原因/解决方案

In my case, the cause was that my server was configured to only accept connections from localhost.就我而言,原因是我的服务器被配置为只接受来自本地主机的连接。 I fixed it by following this article: How Do I Enable Remote Access To MySQL Database Server?我按照这篇文章修复了它: 如何启用对 MySQL 数据库服务器的远程访问? . . My my.cnf file had no skip-networking line, so I just changed the line我的my.cnf文件没有skip-networking行,所以我只是更改了行

bind-address = 127.0.0.1

to

bind-address = 0.0.0.0

This allows connections from any IP, not just 127.0.0.1.这允许来自任何 IP 的连接,而不仅仅是 127.0.0.1。

Then, I created a MySql user that could connect from my client machine by running the following terminal commands:然后,我创建了一个 MySql 用户,该用户可以通过运行以下终端命令从我的客户端计算机进行连接:

# mysql -u root -p
mysql> CREATE USER 'username'@'1.2.3.4' IDENTIFIED BY 'password';
    -> GRANT ALL PRIVILEGES ON *.* TO 'username'@'1.2.3.4' WITH GRANT OPTION;
    -> \q

where 1.2.3.4 is the IP of the client you are trying to connect from.其中1.2.3.4是您尝试连接的客户端的 IP。 If you really have trouble, you can use '%' instead of '1.2.3.4' to allow the user to connect from any IP.如果你真的有问题,你可以使用'%'而不是'1.2.3.4'来允许用户从任何IP连接。

Other Causes其他原因

For a fairly extensive list, see Causes of Access-Denied Errors .有关相当广泛的列表,请参阅拒绝访问错误的原因

Did you try to determine if this is a problem with Workbench or a general connection problem?您是否尝试确定这是 Workbench 的问题还是一般的连接问题? Try this:尝试这个:

  1. Open a terminal打开终端
  2. Type mysql -u root -p -h 127.0.0.1 -P 3306键入mysql -u root -p -h 127.0.0.1 -P 3306
  3. If you can connect successfully you will see a mysql prompt after you type your password (type quit and Enter there to exit).如果您可以成功连接,您将在输入密码后看到 mysql 提示(输入quit并在此处输入退出)。

Report back how this worked.报告这是如何工作的。

I had a similar issue on Mac OS and I was able to fix it this way:我在Mac OS上遇到了类似的问题,我可以通过这种方式修复它:

From the terminal, run:从终端运行:

mysql -u root -p -h 127.0.0.1 -P 3306

Then, I was asked to enter the password.然后,我被要求输入密码。 I just pressed enter since no password was setup.因为没有设置密码,所以我只是按了Enter

I got a message as follows:我收到一条消息如下:

Welcome to the MySQL monitor.欢迎使用 MySQL 监视器。 Commands end with ;命令以 ; 结尾or \g.或\g。 Your MySQL connection id is 181. Server version: 8.0.11 Homebrew.您的 MySQL 连接 ID 是 181。服务器版本:8.0.11 Homebrew。

If you succeeded to log into mysql>, run the following command:如果您成功登录到 mysql>,请运行以下命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

You should get a message like this:你应该收到这样的消息:

Query OK, 0 rows affected (0.19 sec)查询正常,0 行受影响(0.19 秒)

Now, your password is " password " and your username is " root ".现在,您的密码是“ password ”,您的用户名是“ root ”。

Happy coding :)快乐编码:)

Run the ALTER USER command.运行 ALTER USER 命令。 Be sure to change password to a strong password of your choosing.请务必将密码更改为您选择的强密码。

  1. sudo mysql # Login to mysql` sudo mysql #登录mysql`

  2. Run the below command运行以下命令

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Now you can access it by using the new password.现在您可以使用新密码访问它。

Ref : https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04参考: https ://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04

I had to start Workbench as Administrator.我必须以管理员身份启动 Workbench。 Apparently it didn't have the required permissions to connect to my localhost database server process.显然它没有连接到我的本地主机数据库服务器进程所需的权限。

Right-click the Workbench shortcut and select Run as Administrator .右键单击 Workbench 快捷方式并选择Run as Administrator In the shortcut's Properties window, you can click on "Advanced" and tick the box next to "Run as Administrator" to always run the Workbench with Admin privileges.在快捷方式的“属性”窗口中,您可以单击“高级”并勾选“以管理员身份运行”旁边的框,以始终以管理员权限运行工作台。

The error occur because the mysql server is not starting on your computer.发生错误是因为 mysql 服务器未在您的计算机上启动。 You should start it manually.您应该手动启动它。 Do following steps:执行以下步骤:

  1. Download and install wamp server according to your bit version(32bit or 64bit) in your computer( http://wampserver-64bit.en.softonic.com/ ) this link allows you to download wamp server for 64bit.根据您计算机中的位版本(32 位或 64 位)下载并安装 wamp 服务器( http://wampserver-64bit.en.softonic.com/ )此链接允许您下载 64 位的 wamp 服务器。

  2. As soon as you install it you can double click and run it..(you can see a icon in the right hand of the taskbar.It may be hidden .so you can click the arrow which show you the hide apps runing).So click the icon and go to Mysql安装后,您可以双击并运行它..(您可以在任务栏的右侧看到一个图标。它可能是隐藏的。因此您可以单击显示隐藏应用程序运行的箭头)。所以单击图标并转到Mysql

  3. Then go to Service and there you can find Start/Resume Services click on it..然后去服务,在那里你可以找到开始/恢复服务点击它..

  4. And now it is done.Open mysql workbench and see.It will work..现在它完成了。打开mysql工作台看看。它会工作..

I struggled with this problem for awhile and did several reinstalls of MySQL before discovering this.我在这个问题上挣扎了一段时间,并在发现这个问题之前重新安装了几次 MySQL。

I know that MySQL server was running OK because I could access all my DB's using the command line.我知道 MySQL 服务器运行正常,因为我可以使用命令行访问我的所有数据库。

Hope this works for you.希望这对你有用。

In MySQL Workbench (5.2.47 CE)MySQL 工作台中 (5.2.47 CE)

click Mange Server Instances (bottom right corner)单击管理服务器实例(右下角)

click Connection单击连接

in the Connection box select:连接框中选择:

Local Instance ($ServerName) - root@127.0.0.1:3306 '<'Standard(TCP/IP)>本地实例 ($ServerName) - root@127.0.0.1:3306 '<'Standard(TCP/IP)>

click Edit Selected...单击编辑所选...

under Parameters, Hostname change localhost or 127.0.0.1 to your NetBIOS name参数下,主机名将localhost 或 127.0.0.1更改为您的 NetBIOS 名称

click Test Connection单击测试连接

If this works for you, great.如果这对你有用,那就太好了。 If not change the hostname back to what it was.如果没有将主机名更改回原来的样子。

Forr me reason was that I tried to use newest MySQL Workbench 8.x to connect to MySQL Server 5.1 (both running on Windows Server 2012).我的原因是我尝试使用最新的 MySQL Workbench 8.x 连接到 MySQL Server 5.1(都在 Windows Server 2012 上运行)。

When I uninstalled MySQL Workbench 8.x and installed MySQL Workbench 6.3.10 it successfully connected to localhost database当我卸载 MySQL Workbench 8.x 并安装 MySQL Workbench 6.3.10 时,它成功连接到localhost数据库

For those who ignored that the initial error message displaying is the following one:对于那些忽略显示的初始错误消息的人如下:

The name org.freedesktop.secrets was not provided by any .service files任何 .service 文件均未提供名称 org.freedesktop.secrets

Make sure to install gnome-keyring using the following确保使用以下命令安装 gnome-keyring

sudo apt install gnome-keyring

I had same problem with Workbench on Ubuntu, problem was with permission.我在 Ubuntu 上的 Workbench 也有同样的问题,问题出在许可上。

  1. Find Workbench app查找 Workbench 应用程序
  2. Click button Permissions单击按钮权限
  3. Give all permission for this app授予此应用的所有权限

在此处输入图像描述

I tried these steps -我尝试了这些步骤 -

Step 1 : Go to Ubuntu Software Center第 1 步:转到Ubuntu 软件中心

Step 2 : Searched for MySql Workbench第 2 步:搜索MySql Workbench

Step 3 : And Click on Permissions第 3 步:然后点击权限

Step 4 : Enable Read, add, change or remove saved passwords第 4 步:启用读取、添加、更改或删除已保存的密码

Then, enter Login Password然后,输入登录密码

And then, I found that my problem solved然后,我发现我的问题解决在此处输入图像描述

I was in similar situations before and last time I found it was some Windows update issue(not sure).之前和上次我都遇到过类似的情况,我发现这是一些 Windows 更新问题(不确定)。 This time, I opened MySQL workbench and found no connection to my local database.这一次,我打开 MySQL 工作台,发现没有连接到我的本地数据库。 I cannot see my tables, but yesterday I could connect to the database.我看不到我的表,但昨天我可以连接到数据库。

I found that my cause is that, after letting my computer sleeping for some time and wake it again, the mysql service is not running.我发现我的原因是,让我的电脑休眠一段时间并再次唤醒后,mysql服务没有运行。 My solution: restart the service named "mysql" and rerun the workbench.我的解决方案:重新启动名为“mysql”的服务并重新运行工作台。 Restarting the service takes a while, but it works.重新启动服务需要一段时间,但它可以工作。

To be up to date for upper versions and later visitors :为更高版本和更高版本的访问者提供最新信息:

Currently I'm working on a win7 64bit having different tools on it including python 2.7.4 as a prerequisite for google android ...目前我正在开发一个win7 64bit,上面有不同的工具,包括python 2.7.4作为google android的先决条件......

When I upgraded from WB 6.0.8-win32 to upper versions to have 64bit performance I had some problems for example on 6.3.5-winx64 I had a bug in the details view of tables (disordered view) caused me to downgrade to 6.2.5-winx64.当我从 WB 6.0.8-win32 升级到更高版本以获得 64 位性能时,我遇到了一些问题,例如在 6.3.5-winx64 上,我在表格的详细信息视图(无序视图)中有一个错误导致我降级到 6.2。 5-winx64。

As a GUI user, easy forward/backward engineering and db server relative items were working well but when we try to Database>Connect to Database we will have Not connected and will have python error if we try to execute a query however the DB server service is absolutely ran and is working well and this problem is not from the server and is from workbench.作为 GUI 用户,简单的前向/后向工程和数据库服务器相关项目运行良好,但是当我们尝试Database>Connect to Database时,我们将Not connected ,如果我们尝试执行查询,则会出现 python 错误但是数据库服务器服务绝对运行并且运行良好,这个问题不是来自服务器,而是来自工作台。 To resolve it we must use Query>Reconnect to Server to choose the DB connection explicitly and then almost everything looks good (this may be due to my multiple db connections and I couldn't find some solution to define the default db connection in workbench).要解决它,我们必须使用Query>Reconnect to Server明确选择数据库连接,然后几乎一切看起来都很好(这可能是由于我的多个数据库连接,我找不到一些解决方案来定义工作台中的默认数据库连接) .

As a note : because I'm using latest Xampp version (even in linux addictively :) ), recently Xampp uses mariadb 10 instead of mysql 5.x causes the mysql file version to be 10 may cause some problems such as forward engineering of procedures which can be resolved via mysql_upgrade.exe but still when we try to check a db connection wb will inform about the wrong version however it is not critical and works well.注意:因为我使用的是最新的 Xampp 版本(即使在 linux 上瘾 :)),最近 Xampp 使用 mariadb 10 而不是 mysql 5.x 导致 mysql 文件版本为 10 可能会导致一些问题,例如程序的正向工程这可以通过mysql_upgrade.exe解决,但是当我们尝试检查数据库连接时,wb 仍然会通知错误的版本,但它并不重要并且运行良好。

Conclusion : Thus sometimes db connection problems in workbench may be due to itself and not server (if you don't have other db connection relative problems).结论:因此有时工作台中的数据库连接问题可能是由于它本身而不是服务器(如果您没有其他数据库连接相关问题)。

My problem was that the MySQL server wasn't actually installed.我的问题是 MySQL 服务器实际上没有安装。 I had run the MySQL Installer, but it didn't install the MySQL server.我已经运行了 MySQL 安装程序,但它没有安装 MySQL 服务器。

I reran the installer, click "Add", and then added MySQL server to the list.我重新运行安装程序,单击“添加”,然后将 MySQL 服务器添加到列表中。 Now it works fine.现在它工作正常。

In my case I have just installed MySQL Workbench but after uninstalling MySQL Workbench and installing MySQL installer and is same for both 32 and 64 bit then after it working like a charm.在我的情况下,我刚刚安装了 MySQL Workbench,但是在卸载 MySQL Workbench 并安装 MySQL 安装程序之后,32 位和 64 位都相同,然后它就像一个魅力一样工作。 Hope it could be useful.希望它可能有用。

The problem is that MYSQL server is not installed.问题是没有安装MYSQL服务器。 You can get the installer from here您可以从这里获取安装程序

Then watch this 6 minute installation tutorial .然后观看这个 6 分钟的安装教程

If then creating a new connection in MYSQL Workbench is not working, make sure you run that connection as root as show below:如果在 MYSQL Workbench 中创建新连接不起作用,请确保以 root 身份运行该连接,如下所示:

在此处输入图像描述

If you don't find your .ini file check this answer.如果您没有找到您的 .ini 文件,请检查此答案。 (also written below) (也写在下面)



    Enter "services.msc" on the Start menu search box.
    Find MySQL service under Name column, for example, MySQL56.
    Right click on MySQL service, and select Properties menu.
    Look for "Path To Executable" under General tab, and there is your .ini file, for instance, "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MYSQL56


Even I faced similar error when I opened MYSQL workbench.即使我在打开 MYSQL 工作台时也遇到了类似的错误。 Solution that worked for me is对我有用的解决方案是

  1. Click on Start button in windows machine单击Windows机器中的开始按钮
  2. Type services and press enter输入服务并按回车
  3. Find MYSQL and click on it找到MYSQL并点击它
  4. On the top side of left panel, you will find a option as Start the service在左侧面板的顶部,您会找到启动服务的选项
  5. Click on Start which is visible as hyperlink单击以超链接形式显示的开始

Hope this might help.希望这可能会有所帮助。

I also struggled with this problem for quite a while.我也为这个问题苦苦挣扎了很长一段时间。

I came accross this interesting thread from MySQL forum: http://forums.mysql.com/read.php?11,11388,11388#msg-11388从 MySQL 论坛遇到了这个有趣的线程:http: //forums.mysql.com/read.php?11,11388,11388#msg-11388

I also came accross (obviously) some good SO Q/A.我也(显然)遇到了一些很好的 SO Q/A。

It seems that the message mentioned in "user948950" 's question can be coming from a wide range of reasons: log file too big, incorrect mysql.ini file values, spaces in the file path, security/acl issue, old entries in the registry, and so on.似乎“user948950”的问题中提到的消息可能来自多种原因:日志文件太大、mysql.ini 文件值不正确、文件路径中有空格、安全/acl 问题、旧条目注册表等。

So, after trying for 3h to fix this... I abandonned and decided to do a good old re-install.所以,在尝试了 3 小时来解决这个问题之后......我放弃并决定重新安装一个好的旧版本。

This is where this post from (again) this MySQL thread came in useful , I quote:这就是(再次)来自这个 MySQL 线程的这篇文章有用的地方,我引用:

Gary Williams wrote: Hi Guys,加里威廉姆斯写道:嗨,伙计们,

I've had exactly the same problem and this is how I got it working for me, starting with a non working installation.我遇到了完全相同的问题,这就是我让它为我工作的方式,从非工作安装开始。

  1. Stop the windows service for any existing mysql installation.停止任何现有 mysql 安装的 windows 服务。

  2. Uninstall Mysql.卸载Mysql。

As with most uninstalls, old files are left behind.与大多数卸载一样,旧文件会被遗留下来。 If your directory is C:\mysql\ etc then delete the innob, etc, files but leave the directories themselves as well as any existing databases in 'data'.如果您的目录是 C:\mysql\ 等,则删除 innob 等文件,但将目录本身以及任何现有数据库保留在“数据”中。 If your directory is C:\Program Files\ etc, delete all the mysql directories.如果您的目录是 C:\Program Files\ 等,请删除所有 mysql 目录。

  1. It's now worth running regedit to make sure the old registry entries are deleted as well by the uninstall.现在值得运行 regedit 以确保旧的注册表项也被卸载删除。 If not, delete them.如果没有,请删除它们。

  2. It's ok to use the new .msi installer (essential files only), however ....可以使用新的 .msi 安装程序(仅限基本文件),但是....

  3. Do not use their default install path!不要使用他们的默认安装路径! Some genius set a path with spaces in it!一些天才设置了一条带有空格的路径! Choose the custom install and select a sensible path, ie, C:\mysql (note from Adrien: C:\mysqldata for ... the data)选择自定义安装并选择一个合理的路径,即 C:\mysql(来自 Adrien 的注释:C:\mysqldata for ... the data)

  4. Do not choose to alter the security settings.不要选择更改安全设置。 Uncheck the relevant box and the install will complete without having to set a root password.取消选中相关框,安装将完成,无需设置 root 密码。

I think I have remembered everything.我想我已经记住了一切。

Good luck祝你好运

Gary加里

I did get into troubles when simply copy/pasting the databases I had in my previous "data" directory to the new one.当简单地将我以前的“数据”目录中的数据库复制/粘贴到新目录中时,我确实遇到了麻烦。 So the work around I found was to export each database (I know... a lot of fun) and then re-import them one by one.所以我发现的解决方法是导出每个数据库(我知道......很有趣),然后一个一个地重新导入它们。

FYI: I used the following command to import C:/<MySQLInstallDir>/My SQL Server xx/bin/mysql -u root -p <dbName> < "<dirPathOfDump>\<dumpName>.sql" , that is for instance C:/mysql/MySQL Server 5.6/bin/mysql -u root -p mySupaCoolDb < "C:\mySupaCoolDbDump20130901.sql"仅供参考:我使用以下命令导入C:/<MySQLInstallDir>/My SQL Server xx/bin/mysql -u root -p <dbName> < "<dirPathOfDump>\<dumpName>.sql" ,例如C:/mysql/MySQL Server 5.6/bin/mysql -u root -p mySupaCoolDb < "C:\mySupaCoolDbDump20130901.sql"

就我而言,安装没有将 MySQL\\MySQL Server 5.7/bin 文件夹添加到我的 PATH 环境变量中。

  1. Right click on your task bar -> Task Manager右键单击任务栏 -> Task Manager

  2. Click on Services button点击Services按钮

  3. Search for MYSQL80 or any other you are using搜索MYSQL80或任何其他您正在使用的

  4. Right Click on MYSQL80 --> Start右键单击MYSQL80 --> Start

This works for me hope it does for you also这对我有用,希望对你也有用

2022 and beyond this works for me: 2022 年及以后这对我有用:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

change改变

bind-address            = 127.0.0.1

to

bind-address            = 0.0.0.0

Then remember to restart mysql sudo systemctl restart mysql然后记得重启mysql sudo systemctl restart mysql

I just put sudo snap connect mysql-workbench-community:ssh-keys sudo snap connect mysql-workbench-community:password-manager-service我只是把 sudo snap connect mysql-workbench-community:ssh-keys sudo snap connect mysql-workbench-community:password-manager-service

initially i was confused but i was able to solve the problem最初我很困惑,但我能够解决问题

if your workbench was downloaded through the snap package-manager you could easily use this command to solve the problem, very simple: sudo snap connect mysql-workbench-community:password-manager-service:password-manager-service如果您的工作台是通过 snap package-manager 下载的,您可以轻松使用此命令来解决问题,非常简单: sudo snap connect mysql-workbench-community:password-manager-service:password-manager-service

Go to services.msc and find MySQL.转到services.msc并找到 MySQL。

If " Log on As " section is 'Network Service', then:如果“登录为”部分是“网络服务”,则:

  1. Double click on the MySQL row to open a pop-up双击 MySQL 行以打开弹出窗口
  2. go to "Log on" tab转到“登录”选项卡
  3. Select Log on as: " Local System account " and check " Allow service to interact with desktop "选择登录为:“本地系统帐户”并勾选“允许服务与桌面交互

Voilà, now you can start your service on localhost and make sure you enter correct root/user password on your MySQL Workbench , and you are good to go.瞧,现在您可以在 localhost 上启动您的服务,并确保在MySQL Workbench上输入正确的 root/用户密码,一切顺利。

If you are using snap to install mysql workbench, try this:如果你使用 snap 安装 mysql workbench,试试这个:

sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service  to allow sandboxed package to access password service

askubuntu.com/a/1242777/1621549 askubuntu.com/a/1242777/1621549

This Solution was made as a comment before by Rohim Chou此解决方案是 Rohim Chou 之前作为评论提出的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM