关于mysql数据库连接问题

2024-11-30 04:59:53
推荐回答(2个)
回答1:

'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)

这里提示是你的密码没有设置成功,所以你用zabbix用户登录时会报错
mysql> grant all on zabbic.* to 'zabbix'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@localhost wwwroot]# mysql -u zabbix -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.50-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

这个就成功了。
后面的你可以把你的sql文件贴出来,报的都是sql文件的错。

回答2:

如果报错的话把错误贴出来,还有就是你倒没倒连接jar包,3个jar加在程序里了吗?
import java.sql.*;
Connection conn =null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/mybbs", "root", "root");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这样可以么?