简体   繁体   English

连接到 MySQL 服务器

[英]Connection to MySQL Server

How am I able to connect to a database even when mysql server is not running?即使 mysql 服务器未运行,我如何能够连接到数据库?

Earlier I was getting error 2003 regarding can't connect to localhost when i used mysql -h localhost -u root -p'mypassword'早些时候can't connect to localhost当我使用mysql -h localhost -u root -p'mypassword'时,我收到了关于can't connect to localhost错误 2003

I searched and found relevant answers at Stack OverFlow and I ensured that MySQL service was running, but still the problem persisted.我在 Stack OverFlow 搜索并找到了相关答案,并确保 MySQL 服务正在运行,但问题仍然存在。

But then I omitted -h localhost from this command and used instead: mysql -u user -p mysql and entered my password as prompted.但是后来我从这个命令中省略了-h localhost并使用了: mysql -u user -p mysql并按照提示输入了我的密码。 Then I was connected to mysql.然后我就连上了mysql。

In other words I can connect with any database in MySQL server even when it's not running using above commands,But still:换句话说,即使没有使用上述命令运行,我也可以连接 MySQL 服务器中的任何数据库,但仍然:

How does all of this is working?这一切是如何运作的?

Type in输入

netstat -tlnp

If you see如果你看到

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1711/mysqld

that means mysql is listening on all interfaces and then loopback should work also, like in my case (i used -h localhost).这意味着 mysql 正在侦听所有接口,然后环回也应该工作,就像在我的情况下一样(我使用了 -h localhost)。

I'm supposing you have disabled logon on loopback and have like 192.168.1.100:3306 for example.我假设您已禁用环回登录,例如 192.168.1.100:3306。

Regards, Mirko问候, 米尔科

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

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