将 MySQL 服务器连接到 NetBeans
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24081719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
connecting MySQL server to NetBeans
提问by user3706280
I am trying to connect MySQL database in Netbeans and stuck at the very first step- connecting the database. My Database is working fine on the console - tried command mysqladmin -u root -p ping and it says mysql id is alive. I have even created database from console. Now when i register it in Netbeans
我正在尝试在 Netbeans 中连接 MySQL 数据库并停留在第一步 - 连接数据库。我的数据库在控制台上运行良好 - 尝试了命令 mysqladmin -u root -p ping 并且它说 mysql id 还活着。我什至从控制台创建了数据库。现在当我在 Netbeans 中注册它时
Server Host Name:localhost
Server Port:3306
Admin user : root
Admin password :<the password which works on console>
and Admin Properties:
和管理属性:
Path to admin tool: C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqladmin.exe
Argument : <blank>
Path to start command:C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe
Argument : --console <as suggested in http://forums.netbeans.org/topic12767.html>
Path to stop command:C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqladmin.exe
Argument : -u root shutdown
but i still get message:- "MySQL Server at localhost:3306 [root] (disconnected)"
但我仍然收到消息:-“本地主机上的 MySQL 服务器:3306 [root](已断开连接)”
if i right click and select "start" or "connect" i get the message in taskbar - Waiting for MYSQL Server to start... for an infinite time.
如果我右键单击并选择“开始”或“连接”,我会在任务栏中收到消息 - 等待 MYSQL Server 启动......无限时间。
Any help what am i doing wrong here???
任何帮助我在这里做错了什么???
回答by ColinWa
Follow these 2 steps:
请按照以下 2 个步骤操作:
STEP 1 :
第1步 :
Follow these steps using the ServicesTab:
使用“服务”选项卡执行以下步骤:
- Right click on Database
- Create new Connection
- 右键单击数据库
- 创建新连接
Customize the New COnnection as follows:
自定义新连接如下:
- Connector Name: MYSQL (Connector/J Driver)
- Host:
localhost
- Port:
3306
- Database:
mysql
( mysql is the default or enter your database name) - Username: enter your database username
- Password: enter your database password
- JDBC URL:
jdbc:mysql://localhost:3306/mysql
- CLick Finishbutton
- 连接器名称:MYSQL(连接器/J 驱动程序)
- 主持人:
localhost
- 港口:
3306
- 数据库:
mysql
(mysql是默认的或者输入你的数据库名) - 用户名:输入您的数据库用户名
- 密码:输入您的数据库密码
- JDBC 网址:
jdbc:mysql://localhost:3306/mysql
- 单击完成按钮
NB:DELETE the ?zeroDateTimeBehaviour=convertToNull
part in the URL.
Instead of mysql
in the URL, you should see your database name)
注意:删除?zeroDateTimeBehaviour=convertToNull
URL 中的部分。mysql
您应该看到您的数据库名称,而不是在 URL 中)
STEP 2 :
第2步 :
- Right click on
MySQL Server at localhost:3306:[username](...)
- Select Properties...from the shortcut menu
- 右键单击
MySQL Server at localhost:3306:[username](...)
- 从快捷菜单中选择属性...
In the "MySQL Server Properties"dialog select the "Admin Properties"tab Enter the following in the textboxes specified:
在“MySQL 服务器属性”对话框中选择“管理属性”选项卡在指定的文本框中输入以下内容:
For Linux users :
对于 Linux 用户:
- Path to start command:
/usr/bin/mysql
- Arguments:
/etc/init.d/mysql start
- Path to Stop command:
/usr/bin/mysql
- Arguments:
/etc/init.d/mysql stop
- 启动命令的路径:
/usr/bin/mysql
- 参数:
/etc/init.d/mysql start
- 停止命令的路径:
/usr/bin/mysql
- 参数:
/etc/init.d/mysql stop
For MS Windows users :
对于 MS Windows 用户:
NOTE: Optional:
注意:可选:
In the Path/URL to admin tool field, type or browse to the location of your MySQL Administration application such as the MySQL Admin Tool, PhpMyAdmin, or other web-based administration tools.
在管理工具的路径/URL 字段中,键入或浏览到 MySQL 管理应用程序的位置,例如 MySQL 管理工具、PhpMyAdmin 或其他基于 Web 的管理工具。
Note: mysqladmin is the MySQL admin tool found in the bin folder of the MySQL installation directory. It is a command-line tool and not ideal for use with the IDE.
注意:mysqladmin是MySQL安装目录bin文件夹下的MySQL管理工具。它是一个命令行工具,不适合与 IDE 一起使用。
Citations:
https://netbeans.org/kb/docs/ide/mysql.html?print=yes
http://javawebaction.blogspot.com/2013/04/how-to-register-mysql-database-server.html
引文:
https: //netbeans.org/kb/docs/ide/mysql.html ? print =
yes http://javawebaction.blogspot.com/2013/04/how-to-register-mysql-database-server.html
We will use MySQL Workbench in this example. Please use the path of your installation if you have MySQL workbench and the path to MySQL.
我们将在本例中使用 MySQL Workbench。如果您有 MySQL 工作台和 MySQL 的路径,请使用您的安装路径。
- Path/URL to admin tool:
C:\Program Files\MySQL\MySQL Workbench CE 5.2.47\MySQLWorkbench.exe
- Arguments:(Leave blank)
- Path to start command:
C:\mysql\bin\mysqld
(ORC:\mysql\bin\mysqld.exe
) - Arguments:(Leave blank)
- Path to Stop command:
C:\mysql\bin\mysqladmin
(ORC:\mysql\bin\mysqladmin.exe
) - Arguments:
-u root shutdown
(Try-u root stop
)
- 管理工具的路径/URL:
C:\Program Files\MySQL\MySQL Workbench CE 5.2.47\MySQLWorkbench.exe
- 参数:(留空)
- 启动命令的路径:(
C:\mysql\bin\mysqld
或C:\mysql\bin\mysqld.exe
) - 参数:(留空)
- 停止命令的路径:(
C:\mysql\bin\mysqladmin
或C:\mysql\bin\mysqladmin.exe
) - 参数:(
-u root shutdown
尝试-u root stop
)
Possible exampes of MySQL bin folder locations for Windows Users:
Windows 用户的 MySQL bin 文件夹位置的可能示例:
C:\mysql\bin
C:\Program Files\MySQL\MySQL Server 5.1\bin\
- Installation Folder:
~\xampp\mysql\bin
C:\mysql\bin
C:\Program Files\MySQL\MySQL Server 5.1\bin\
- 安装文件夹:
~\xampp\mysql\bin
回答by LMG
Fist of all make sure your SQL server is running. Actually I'm working on windows and I have installed a nice tool which is called MySQL workbench (you can find it herefor almost any platform ).
首先确保您的 SQL 服务器正在运行。实际上,我正在 Windows 上工作,并且我安装了一个很好的工具,称为 MySQL 工作台(您可以在此处找到几乎适用于任何平台的工具)。
Thus I just create a new database to test the connection, let's call it stackoverflow, with one table called user.
因此,我只是创建了一个新数据库来测试连接,我们称其为 stackoverflow,其中有一个名为 user 的表。
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
DROP SCHEMA IF EXISTS `stackoverflow` ;
CREATE SCHEMA IF NOT EXISTS `stackoverflow` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `stackoverflow` ;
-- -----------------------------------------------------
-- Table `stackoverflow`.`user`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `stackoverflow`.`user` ;
CREATE TABLE IF NOT EXISTS `stackoverflow`.`user` (
`iduser` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(75) NOT NULL,
`email` VARCHAR(150) NOT NULL,
PRIMARY KEY (`iduser`),
UNIQUE INDEX `iduser_UNIQUE` (`iduser` ASC),
UNIQUE INDEX `email_UNIQUE` (`email` ASC))
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
You can reduce important part to
您可以将重要部分减少到
CREATE SCHEMA IF NOT EXISTS `stackoverflow`
CREATE TABLE IF NOT EXISTS `stackoverflow`.`user` (
`iduser` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(75) NOT NULL,
`email` VARCHAR(150) NOT NULL,
PRIMARY KEY (`iduser`),
UNIQUE INDEX `iduser_UNIQUE` (`iduser` ASC),
UNIQUE INDEX `email_UNIQUE` (`email` ASC))
So now I have my brand new stackoverflow database. Let's connect to it throught Netbeans. Launch netbeans and go to the services panel Now right click on databases: new connection.. Choose MySql connector, they already come packed with netbeans.
Then fill in the gaps the data you need. As shown in the picture add the database name and remove from the connection url the optional parameters as
l?zeroDateTimeBehaviour=convertToNull
. Use the right user name and password and test the connection.
所以现在我有了我全新的 stackoverflow 数据库。让我们通过 Netbeans 连接到它。启动 netbeans 并转到服务面板现在右键单击数据库:新连接.. 选择 MySql 连接器,它们已经包含了 netbeans。
然后填写您需要的数据的空白。如图所示添加数据库名称并从连接url中删除可选参数为
l?zeroDateTimeBehaviour=convertToNull
。使用正确的用户名和密码并测试连接。
As you can see connection is successful.
如您所见,连接成功。
Click FINISH.
单击完成。
You will have your connection successfully working and available under the services.
您的连接将成功运行并在服务下可用。
回答by Erik
check the context.xml
file in Web Pages -> META-INF, the username="user"
must be the same as the database user, in my case was root, that solved the connection error
检查context.xml
文件的Web页面- > META-INF,则username="user"
必须是相同的数据库用户,在我的情况是根本,是解决连接错误
Hope helps
希望有帮助
回答by user7288944
in my cases, i found my password in glassfish-recources.xml under WEB-INF
就我而言,我在 WEB-INF 下的 glassfish-reources.xml 中找到了我的密码
回答by Iman Ravakhah
Close NetBeans.
Stop MySQL Server.
Update MySQL (if available)
Start MySQL Server.
Open NetBeans.
关闭 NetBeans。
停止 MySQL 服务器。
更新 MySQL(如果可用)
启动 MySQL 服务器。
打开 NetBeans。
If still doesn't connect, download MySQL Connector/Jand add mysql-connector-java-[version].jar to your
classpathand also to your Webserver's libdirectory. For instance, Tomcat lib path
in XAMPP is
C:\xampp\tomcat\lib.
Then repeat the steps again.
如果仍然无法连接,请下载MySQL Connector/J并将 mysql-connector-java-[version].jar 添加到您的
类路径以及您的Web 服务器的 lib目录中。例如,XAMPP 中的 Tomcat 库路径是
C:\xampp\tomcat\lib。
然后再次重复这些步骤。
回答by Claudio Abud
I just had the same issue with Netbeans 8.2 and trying to connect to mySQL server on a Mac OS machine. The only thing that worked for me was to add the following to the url of the connection string: &serverTimezone=UTC (or if you are connecting via Hibernate.cfg.xml then escape the & as &) Not surprisingly I found the solution on this stack overflow post also:
我刚刚在 Netbeans 8.2 上遇到了同样的问题,并尝试在 Mac OS 机器上连接到 mySQL 服务器。唯一对我有用的是将以下内容添加到连接字符串的 url 中:&serverTimezone=UTC(或者,如果您通过 Hibernate.cfg.xml 连接,则将 & 转义为 &) 毫不奇怪我找到了解决方案堆栈溢出帖子也:
MySQL JDBC Driver 5.1.33 - Time Zone Issue
Best Regards, Claudio
最好的问候,克劳迪奥
回答by Aanal Suthar
- Download XAMPP
- Run XAMPP server. Click on Start button in front of MY SQL. Now you can see that color is changed to green. Now, Click on Admin.The new browser window will be open. Copy the link from browser and paste to the Admin properties as shown in below. Set path in the admin properties of database connection. Click on OK. Now your database is connected. enter image description here
- 下载 XAMPP
- 运行 XAMPP 服务器。单击 MY SQL 前面的开始按钮。现在您可以看到颜色变为绿色。现在,单击 Admin。新的浏览器窗口将打开。从浏览器复制链接并粘贴到管理属性,如下所示。在数据库连接的管理属性中设置路径。单击确定。现在您的数据库已连接。 在此处输入图片说明