मैं उबंटू चला रहा हूं और आखिरकार जेएमबीसी का उपयोग कर टॉमकैट को अपने MySQL डेटाबेस से कनेक्ट करने का प्रयास कर रहा हूं।जेडीबीसी के साथ MySQL से कनेक्ट नहीं हो सकता - कनेक्शन टाइमआउट - उबंटू 9.04
यह पहले पर काम किया है लेकिन रीबूट के बाद उदाहरण अब कनेक्ट करने में विफल रहता है। JDBC:
- दोनों बिलाव 6 और MySQL 5.0.75 एक ही मशीन
- कनेक्शन स्ट्रिंग पर हैं mysql: /// स्थानीय होस्ट: 3306
- मैं
mysql
का उपयोग कर कमांड लाइन पर MySQL से कनेक्ट कर सकते आदेश - my.cnf फ़ाइल सुंदर मानक (अनुरोध पर उपलब्ध है) के लिए बाध्य किया गया है पता है: 127.0.0.1
- मैं netstat MySQL कह के बावजूद MySQL बंदरगाह नहीं टेलनेट
- सुन रहा है मैं अग्रेषित करने के लिए एक iptables नियम है 80 -> 8080 और कोई फ़ायरवॉल मुझे पता है।
मैं इस पर बहुत नया हूं और मुझे यकीन नहीं है कि परीक्षण करने के लिए और क्या है। मुझे नहीं पता कि मुझे आदि/इंटरफेस में देखना चाहिए या नहीं और यदि मैंने ऐसा किया तो मैंने क्या किया। यह अजीब है क्योंकि यह काम करता था लेकिन रीबूट के बाद यह नीचे है इसलिए मैंने कुछ बदलना होगा .... :)।
मुझे लगता है कि एक टाइमआउट इंगित करता है कि सर्वर प्रतिक्रिया नहीं दे रहा है और मुझे लगता है कि यह अनुरोध वास्तव में नहीं हो रहा है। मैंने apt-get और टोमकैट मैन्युअल रूप से MySQL स्थापित किया।
mysqld प्रक्रियाओं
[email protected]:/var/log/mysql# ps -ef | grep mysqld
root 21753 1 0 May27 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe
mysql 21792 21753 0 May27 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root 21793 21753 0 May27 ? 00:00:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
root 21888 13676 0 11:23 pts/1 00:00:00 grep mysqld
Netstat
[email protected]:/var/log/mysql# netstat -lnp | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 21792/mysqld
unix 2 [ ACC ] STREAM LISTENING 1926205077 21792/mysqld /var/run/mysqld/mysqld.sock
खिलौना कनेक्शन कक्षा
[email protected]:~# cat TestConnect/TestConnection.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class TestConnection {
public static void main(String args[]) throws Exception {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Got driver");
con = DriverManager.getConnection(
"jdbc:mysql:///localhost:3306",
"uname", "pass");
System.out.println("Got connection");
if(!con.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
} finally {
if(con != null)
con.close();
}
}
}
खिलौना कनेक्शन कक्षा आउटपुट
नोट: यह वही त्रुटि है जो मुझे टॉमकैट से मिलती है।
[email protected]:~/TestConnect# java -cp mysql-connector-java-5.1.12-bin.jar:. TestConnection
Got driver
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 1 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
at TestConnection.main(TestConnection.java:14)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2181)
... 12 more
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
... 13 more
टेलनेट आउटपुट
[email protected]:~/TestConnect# telnet localhost 3306
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection timed out
यह मुझे उस उत्तर में ले जाता है जो कि लो इंटरफ़ेस नीचे था। * शर्म में सिर लटका *। एक त्वरित 'ifconfig lo up' इसे सॉर्ट किया गया। – gav