你的配置文件修改之前,至少要备份一下,要知道自己改了哪些地方,好有个对照. 另外,你描述问题并不是非常明晰,大家伙儿想帮你,也不知道该如何帮.1. 先保证你的mysql服务能起起来. 2. 用命令行,加上你自己要用的用户名和密码,测试一下是否连接成功. 3. 确保你用的mysql jdbc driver版本是适宜的. 其实,我基本上可以推断出,你用的driver版本不太合适,换一个新一点的版本吧. 我的问题就是我通过java去操作数据库,但是在建立连接的时候就报出上述错误了。后来我去搜索,发现这个问题很多,然后按照网上的解决办法都试过了,就是不好使。现在服务能起来,而且用户名和密码正确,至于版本的话是的,我因为昨天就怀疑是版本问题了,所以去官网更新了,现在版本是5.1.28。 我my.cnf的配置数据:# # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html# This will be passed to all mysql clients # It has been reported that passwords should be enclosed with ticks/quotes # escpecially if they contain "#" chars... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. [client] port = 3306 socket = /var/run/mysqld/mysqld.sock# Here is entries for some specific programs # The following values assume you have at least 32M ram# This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0[mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysqlwait_timeout = 2147483 interactive_timeout = 2147483skip-external-locking# # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 10.0.1.146 # # * Fine Tuning # key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP #max_connections = 100 #table_cache = 64 #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 1M query_cache_size = 16M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! #general_log_file = /var/log/mysql/mysql.log #general_log = 1 # # Error log - should be very few entries. # log_error = /var/log/mysql/error.log # # Here you can see queries with especially long duration #log_slow_queries = /var/log/mysql/mysql-slow.log #long_query_time = 2 #log-queries-not-using-indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem[mysqldump] quick quote-names max_allowed_packet = 16M[mysql] #no-auto-rehash # faster start of mysql but no tab completition[isamchk] key_buffer = 16M# # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/我几乎没做修改,就[mysqld]部分的wait_timeout和interactive_timeout是我看网上解决方面加进去的。 java连接数据库部分:private static final String key = "order_id"; private static final String value = "product";
private static final String url = "jdbc:mysql://localhost:3306/test"; private static final String user = "root"; private static final String pass = "root";
private static Connection conn = null;
static void init() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println("*******"); conn = (Connection)DriverManager.getConnection(url,user,pass); System.out.println("&&&&&&&&"); }catch(SQLException e) { e.printStackTrace(); }catch(ClassNotFoundException e) { e.printStackTrace(); }catch(IllegalAccessException e) { e.printStackTrace(); }catch(InstantiationException e) { e.printStackTrace(); } }niuguoqin@ubuntu:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 37 Server version: 5.5.34-0ubuntu0.12.10.1 (Ubuntu)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trade of Oracle Corporation and/or its affiliates. Other names may be trades of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
我找到原因了:# # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 10.0.1.146你把这一行注掉,就行了. 不用换driver了.
conn = (Connection)DriverManager.getConnection(url,user,pass);我经过跟踪找到了就是执行这句的时候抱出来的的错误,我google说是mysql的连接问题,提供的那些方法每一个好使的。
我经过跟踪找到了就是执行这句的时候抱出来的的错误,我google说是mysql的连接问题,提供的那些方法每一个好使的。
你的配置文件修改之前,至少要备份一下,要知道自己改了哪些地方,好有个对照.
另外,你描述问题并不是非常明晰,大家伙儿想帮你,也不知道该如何帮.1. 先保证你的mysql服务能起起来.
2. 用命令行,加上你自己要用的用户名和密码,测试一下是否连接成功.
3. 确保你用的mysql jdbc driver版本是适宜的.
其实,我基本上可以推断出,你用的driver版本不太合适,换一个新一点的版本吧.
你的配置文件修改之前,至少要备份一下,要知道自己改了哪些地方,好有个对照.
另外,你描述问题并不是非常明晰,大家伙儿想帮你,也不知道该如何帮.1. 先保证你的mysql服务能起起来.
2. 用命令行,加上你自己要用的用户名和密码,测试一下是否连接成功.
3. 确保你用的mysql jdbc driver版本是适宜的.
其实,我基本上可以推断出,你用的driver版本不太合适,换一个新一点的版本吧.
我的问题就是我通过java去操作数据库,但是在建立连接的时候就报出上述错误了。后来我去搜索,发现这个问题很多,然后按照网上的解决办法都试过了,就是不好使。现在服务能起来,而且用户名和密码正确,至于版本的话是的,我因为昨天就怀疑是版本问题了,所以去官网更新了,现在版本是5.1.28。
我my.cnf的配置数据:#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock# Here is entries for some specific programs
# The following values assume you have at least 32M ram# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysqlwait_timeout = 2147483
interactive_timeout = 2147483skip-external-locking#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 10.0.1.146
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem[mysqldump]
quick
quote-names
max_allowed_packet = 16M[mysql]
#no-auto-rehash # faster start of mysql but no tab completition[isamchk]
key_buffer = 16M#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/我几乎没做修改,就[mysqld]部分的wait_timeout和interactive_timeout是我看网上解决方面加进去的。
java连接数据库部分:private static final String key = "order_id";
private static final String value = "product";
private static final String url = "jdbc:mysql://localhost:3306/test";
private static final String user = "root";
private static final String pass = "root";
private static Connection conn = null;
static void init() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("*******");
conn = (Connection)DriverManager.getConnection(url,user,pass);
System.out.println("&&&&&&&&");
}catch(SQLException e) {
e.printStackTrace();
}catch(ClassNotFoundException e) {
e.printStackTrace();
}catch(IllegalAccessException e) {
e.printStackTrace();
}catch(InstantiationException e) {
e.printStackTrace();
}
}niuguoqin@ubuntu:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.5.34-0ubuntu0.12.10.1 (Ubuntu)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trade of Oracle Corporation and/or its
affiliates. Other names may be trades of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
你用的5.1.28的jdbc jar,对吧?
不妨试一下这个版本的:
mysql-connector-java-5.1.6-bin
在同一台机器上命令行能连通,jdbc没有理由连不能.
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 10.0.1.146你把这一行注掉,就行了.
不用换driver了.