如何连接到MySQL服务器 [英] how to connect to a MySQL server

查看:93
本文介绍了如何连接到MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,关于此过程,我是一个完整的新手.

我一直在努力建立与使用MySQL Workbench建立的本地SQL服务器的连接.我确定我的SQL服务器正在运行,因为我可以在控制面板"-管理工具"中设置ODBC数据源,并且该数据库连接到我的本地服务器(它还会列出我的数据库).

现在涉及到delphi XE-5.我以为建立连接就像使用端口,登录名和密码登录IP一样容易,但是经过2天的阅读和尝试后,我发现无知是一种幸福.

所以somone可以逐步告诉我要使用什么连接器以及如何进行设置.我的exe文件夹中需要什么可能的dll和/或驱动程序文件.如何告诉我的应用程序在那里.以及其他我可能缺少的东西.

预先感谢

解决方案

对此的最可能的解释可能是您正在使用的libmysql.dll版本与您的DBX设置不匹配,特别是它的mySql驱动程序.对于XE6,我在查找您的问题时遇到了这个问题,其原因是我试图使用的libmysql.dll版本显然对于XE6 DBX驱动程序来说太新了.不管是否正确,下面的步骤都可以解决我的XE6的问题.

(读者注意到q上的XE5标签,并且没有D7,当他们第一次看到这主要是关于D7时,可能会发现他们的鼠标朝着-1按钮移动.当前的许多SO Delphi qs都是D7用户提供的,我敢肯定我不是唯一一个将mySql改造为D7中的DBX的人.某个对mySql更加熟悉的人可能会说,仅对于XE5/6来说它们就算是过大了.

这个Q启发了我尝试让mySql在D7和XE6上工作,而以前对此却一无所知.

关于D7,很快我发现自己为自己制造了一个问题当D7在14年前是最新版本时,没有得到libMySql.dll的副本.我还在EMBA的奎因·维尔德曼(Quinn Wildman)的EMBA新闻组中找到有关XE6和DLL最新版本的问题的帖子,并说在这种情况下,OP的DLL版本太新.

我第一次安装mySql的尝试-基本上是通过安装当前mySqll Workbench的副本-似乎证实了QW所说的;我无法使用随附的libmysql版本在D7或XE6中打开TSqlConnection.幸运的是,mySql网站上有一个档案,我找到并安装了Workbench的早期版本5.0.18,该版本具有2006年版本的libmySql.dll(顺便说一句,与以前的版本不同,我发现该Workbench的早期版本几乎无法使用).当前的故事,但这是另一回事了.

获取和安装WB的较新版本(例如5.0.18)附带的libmysq.dll可能是从太新的版本回滚以使其能够与XE5或6一起工作的全部必要./p>

要使它与D7一起使用非常棘手,因为D7不支持开箱即用的mySqlv5.x.幸运的是,有一个站点带有用于D7的v5 DBX驱动程序.但是即使配备了该功能,仍然可以使mySql的v5.x与D7协同工作.我敢说熟悉mySql的人可能知道更简单的方法,但是至少下面的方法有效.

从完全从Win7 64位计算机上卸载了mySql开始,如下较早的尝试失败,并且删除了C:\ Users [...]下面的所有mySql内容(包括任何mySql数据库文件):

  1. a)转到 http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html 并下载源和dll zip文件.您需要源zip中的ini文件.

    b)打开源zip,并按照dbxdrivers.ini中的说明将驱动程序设置复制到Delphi 7安装目录下\ Shared \ DBExpress文件夹中的同名ini文件中.不要忘记将驱动程序名称添加到dbxdrivers.ini文件顶部的列表中.

    c)同样,将dbxconnections.ini的内容从源zip编辑到其中一个[...] \ Shared \ DBExpress

  2. 如果您没有帐户,请访问www.Mysql.com,创建一个帐户.下载最新版本的MySql Workbench(截至2014年7月22日,适用于MySql的6.1转到存档选项卡,然后下载Workbench 5.0.18.

  3. 安装早期版本的Workbench 5.0.18

  4. 从5.0.18文件夹下的程序文件(x86)\ MySql下的其他位置复制libmysql.dll,因为下一步将删除原始的在那里(!)

  5. 安装更高版本的Workbench,如果以前未设置MySql,则安装启动,允许安装程序向导设置新的本地服务器.设置root密码并创建一个用户帐户.我称我为"sa".

  6. 使用Workbench中的Sql Script窗口创建测试数据库,我使用MATestDB之所以命名,是因为已经有一个名为"test"的文件,并在其中创建了一个表并添加几行.

  7. 将dbxopenmysql50.dll从步骤1中的dll zip复制到步骤1中提到的Borland Shared \ DBExpress目录中

  8. 转到Shared \ DBExpress目录并编辑两个ini文件,以使数据库,用户名和密码与步骤5和6中的相对应.

  9. 在D7 IDE中创建一个新项目,并在其主窗体中添加一个TSqlConnection.检查是否可以将其Connected属性设置为True.

  10. 将项目保存到新文件夹并复制到它

    • 第4步中保存的libmysql.dll
    • 步骤1中dll zip中的
    • dbxopenmysql50,dll
    • [...] \ Shared \ DBExpress中的两个ini文件
  11. 为XE6重复步骤9和10.

  12. 现在应该为D7和XE6设置
  13. mySql.

First of all, I'm a complete novice when it comes to this procedure.

I've been working on setting up a connection to my local SQL server I've set up using MySQL Workbench. I'm sure my SQL server is running, because I can set up an ODBC DataSource in Control Panel - Administrative Tools, and this connects to my local server (it also lists my databases).

Now it comes to delphi XE-5. I figured setting up a connection would be as easy as logging in to an IP with port, login name and password but after 2 days of reading and trying out I figured that ignorance is blissed.

So can somone tell me step-by-step what connector to use and how to set it up. What possible dll's and/or driver files I need in my exe folder. How to tell my app that there there. And possible other stuff I'm missing.

Thanks in advance

解决方案

The most likely explanation of this is probably that there is a mis-match between the version of libmysql.dll you're using and your DBX set-up, in particular its driver for mySql. For XE6, where I ran into this problem looking into yours, the cause was that the version of the libmysql.dll I was trying to use is apparently too recent for the XE6 DBX driver; whether that is correct or not, the steps below solve the problem for my XE6.

(Readers noting the XE5 tag on the q and the absence of a D7 one might find their mouse twitching towards the -1 button when they first see that this is mostly about D7. However, many of the current SO Delphi qs are from D7 users, and I'm sure I'm not the only one who'll ever face the problem of retro-fitting mySql to DBX in D7; someone more familiar with mySql would probably say they are overkill just for XE5/6.)

This Q inspired me to try getting mySql working with D7 and XE6, with no previous knowledge of it.

Regarding D7, it soon turned out that I had created a problem for myself by not getting a copy of libMySql.dll when D7 was current 14 years ago. I also found a post in the EMBA newsgroups from Quinn Wildman of EMBA about a problem with XE6 and the most recent versions of the dll, saying that the OP in that case had a too-recent version of the DLL.

My first attempt at installing mySql - basically by installing a copy of the current mySqll Workbench - seemed to confirm what QW said; I couldn't open a TSqlConnection in D7 or XE6 using the version of libmysql that comes with it. Fortunately the mySql website has an archive and I found and installed an earlier version of the Workbench, 5.0.18, which had a 2006 version of the libmySql.dll (btw, I found this earlier version of Workbench almost unfathomable to use, unlike the current one, but that's another story).

Getting and installing the libmysq.dll that comes with an less recent version of WB, such as 5.0.18 is probably all that's necessary to to roll back from at too-recent version to get it working with XE5 or 6.

Getting it working with D7 turned out to be considerably trickier, because D7 didn't support v5.x of mySql out of the box. Fortunately there is a site with a v5 DBX driver for D7. but even equipped with that, it was still a bit of a performance to get v5.x of mySql working with D7. I dare say someone familiar with mySql might know a simpler way, but at least the method below worked.

Starting with mySql completely uninstalled from my Win7 64-bit machine, following earlier failed attempts, and with all the mySql stuff below C:\Users[...] deleted (including any mySql database files):

  1. a) Go to http://www.justsoftwaresolutions.co.uk/delphi/dbexpress_and_mysql_5.html and download the source and dll zip files. You need the ini files in the source zip.

    b) Open the source zip and follow the instructions in the dbxdrivers.ini to copy the driver settings to the ini file of the same name in the \Shared\DBExpress folder under the Delphi 7 install directory. Don't forget to add the driver name to the list at the top of the dbxdrivers.ini file.

    c) Likewise edit the contents of dbxconnections.ini from the source zip into the one in [...]\Shared\DBExpress

  2. Go to www.Mysql.com, create an account if you don't aready have one. Download the current version of MySql Workbench (6.1 for MySql as at 22 Jul 2014 Go to the archive tab and download Workbench 5.0.18.

  3. Install the earlier 5.0.18 version of Workbench

  4. Make a copy of libmysql.dll from 5.0.18's folder under program files(x86)\MySql somewhere else, because the next step will remove the original there(!)

  5. Install the later version of Workbench and, if MySql hasn't previously been set up, allow the installer wizard to set up a new local server. Set root password and create a user account. I called mine 'sa'.

  6. Use the Sql Script window in Workbench to create a test database, I used MATestDB as the name because there was already one called 'test', and create a table in it and add a few rows.

  7. Copy dbxopenmysql50.dll from the dll zip in step 1 to the Borland Shared\DBExpress directory mentioned in step 1

  8. Go to the Shared\DBExpress directory and edit the two ini files so that the database, user name and password correspond with the ones in steps 5 and 6.

  9. In the D7 IDE create a new project and add a TSqlConnection to its main form. Check that you can set its Connected property to True.

  10. Save the project to a new folder and copy to it

    • libmysql.dll saved from step 4
    • dbxopenmysql50,dll from the dll zip in step 1
    • the two ini files from [...]\Shared\DBExpress
  11. Repeat steps 9 and 10 for XE6.

  12. mySql for D7 and XE6 should all now be set up.

这篇关于如何连接到MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆