1.安装后第一次打开会弹出此框要求你连接mysql。连接名随便填,password 默认为 root.

2.完成之后,进入主界面你会看到你刚看创建的Connection.(这里我创建的连接名字为DB)

3.打开DB,你会发现里面有几个已经创建的数据库,这是系统自动帮你创建的,不用管他。
4.接下来,创建自己需要的数据库。右击->new Database:

Default Character Set 选择utf8.
Default Collation 选择utf8_bin.
这样选择可以避免出现中文乱码出现。
5.接下来在我们刚才创建的数据库下建表。
右键->new table:

在这个表中,我建立了三个域,ID,adminName,password。
在此界面下可以选择类型,长度,小数点后长度,是否为空,和设置为主键等功能。
选中一个域后,还可以在界面底部设置其他属性,有默认值,Comment,Column Format等
这里我给ID设为自增长。
6.之前说过mysql会有出现中文乱码的情况。在这个表中的adminName域则可能存在中文。
避免乱码,(对每一个用到中文的域)同时字符编码也要进行如下设置,点击adminName:

7.最后在options选择中同样的设置字符编码如下。

点击save:

创建成功。
特别注意,最后在使用JDBC连接数据库时url应当在后面加上?useUnicode=true&characterEncoding=UTF-8
如下:
public class ConnectDB {
public static Connection getConnection() {
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
//-----在url后面添加useUnicode=true&characterEncoding=UTF-8这些参数是为了让mysql数据库可以识别中文-----
String url = "jdbc:mysql://localhost:3306/vote?useUnicode=true&characterEncoding=UTF-8";
String username = "root";
String password = "root";
try {
connection = DriverManager.getConnection(url,username,password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}
}
连接数据库时出现的问题:
:
这种情况有人说是没有给root分配权限,有人说是密码不正确。
这个我还不敢断定。
我的解决办法是修改密码。在navicat下修改密码很简单
在User下找到与上面对应出异常的用户。这里是root@localhost
点击进入:

在password 和 Confirm password 两项中填入root.

save即可解决问题。
网友评论
推荐下,分库分表中间件 Sharding-JDBC 源码解析 17 篇:http://www.yunai.me/categories/Sharding-JDBC/?jianshu&401
的
Access denied for user 'root'@'localhost' (using password: YES)
麻烦请教下,谢谢啦
或密码错了