简体   繁体   English

连接到MySQL数据库

[英]Connecting to MySQL db

When I attempt to connect from Windows 7 using 32bit and 64bit mysql-connector-odbc-5.3.2 and the connectionstring: 当我尝试使用32位和64位mysql-connector-odbc-5.3.2和connectionstring从Windows 7连接时:

Provider=MSDASQL;Driver={MySQL ODBC 5.3 Driver};Server=192.168.1.13;Port=3306;Database=mydb;Uid=root;Pwd=****;

I get 我懂了

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Likewise with version 5.2.6. 对于5.2.6版也是如此。 After downgrading the provider to 5.1 I get: 将提供程序降级到5.1后,我得到:

[MySQL][ODBC 5.1 Driver]Can't connect to MySQL server on '192.168.1.13' (10060)

which is more encouraging as it has at least recognised the provider. 这更令人鼓舞,因为它至少已经认可了提供者。

I have tried adding a firewall rule to allow outbound connections to port 3306. I've tried disabling my local firewall. 我尝试添加防火墙规则以允许到端口3306的出站连接。我尝试禁用本地防火墙。 I have checked that the server is listening on port 3306 and verified the IP address. 我检查了服务器是否正在侦听端口3306并验证了IP地址。 (tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN) I have further verified that I can access the server and that MySQL is running. (tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN)我进一步验证了我可以访问服务器并且MySQL正在运行。

When I attempted to connect using the IP address from an ssh terminal to the server itself: mysql -u root -h 192.168.1.13 -D whiskeywheel -p 当我尝试使用IP地址从ssh终端连接到服务器本身时:mysql -u root -h 192.168.1.13 -D whiskeywheel -p

I am prompted for the password after which I get: ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.13' (111) 系统提示我输入密码,然后输入:ERROR 2003(HY000):无法连接到“ 192.168.1.13”上的MySQL服务器(111)

I have added the host/user to the user table in the mysql database and restarted MySQL. 我已经将主机/用户添加到mysql数据库的用户表中,然后重新启动了MySQL。 I've granted 'ALL' on the database to the user at anyhost ('%') and I've explicitly added access to port 3306 to the ubuntu firewall: iptables -A INPUT -p tcp --dport 3306 -j ACCEPT 我已将数据库上的“ ALL”授予所有主机('%')处的用户,并且已将对端口3306的访问权限明确添加到ubuntu防火墙:iptables -A INPUT -p tcp --dport 3306 -j ACCEPT

I will of course restrict access prior to deployment but I need to be able to interact with the database in a meaningful form while I'm developing it. 我当然会在部署之前限制访问,但是在开发数据库时,我需要能够以有意义的形式与数据库进行交互。 I'm happy to re install any of the various components and start again as this is early enough in the project but ideally I'd like to know what I've misconfigured or where I went wrong. 我很高兴重新安装所有各种组件,然后重新开始,因为这在项目中已经足够早了,但理想情况下,我想知道自己配置错误或出了什么问题。

mysql server by default only bind to the loopback address on the sever (127.0.0.1). 默认情况下,mysql服务器仅绑定到服务器(127.0.0.1)上的回送地址。 you have to edit the my.cnf file of the server and do a restart of the mysql server. 您必须编辑服务器的my.cnf文件并重新启动mysql服务器。

also note that specifying localhost is treated special by mysql server. 还要注意,指定localhost被mysql服务器认为是特殊的。 it does not call 127.0.0.1 as one would expects. 它不会像人们期望的那样调用127.0.0.1。

more info here on how to bind to your external ipaddress: 有关如何绑定到您的外部ipaddress的更多信息,请参见:

http://www.cyberciti.biz/faq/unix-linux-mysqld-server-bind-to-more-than-one-ip-address/ http://www.cyberciti.biz/faq/unix-linux-mysqld-server-bind-to-more-than-one-ip-address/

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

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