使用MySQL客户端远程连接Lunarpages数据库

Posted by dohkoos on July 9th, 2009 (658 views)

Lunarpages虚拟主机上的MySQL服务默认仅有本机能访问。只有在cPanel中向某ip地址或地址段或者所有ip地址开放访问权限后,才可以从外部用客户端连接到数据库。

如果想允许任何主机的访问,直接在Host处填写百分号%,然后Add Host即可。如果只想特定主机访问,就输入客户端机器的ip地址。
lunarpages-mysql-remote

还有就是客户端远程连接时使用的地址就是空间的ip地址,可以通过ping域名得到。

Related Posts

Ubuntu 8.10下安装Rails的MySQL驱动

Posted by dohkoos on February 23rd, 2009 (1,263 views)

要安装MySQL,可以在终端提示符后运行下列命令(它会自动安装mysql-client包),按照提示输入root用户的密码:
$ sudo apt-get install mysql-server

$ mysql --version
mysql  Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (i486) using readline 5.2

在安装好后我就开始了Rails的学习,结果在rake db:create时出现了下面的警告:
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql

(See full trace by running task with --trace)

大概意思是说从Rails 2.2开始mysql.rb驱动已经被移除了,需要另外安装该gem文件。

$ sudo gem install mysql

结果出现了下面的错误:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install mysql
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

这是怎么一回事呢?搜索了一把,发现是没有安装ruby1.8-dev的缘故。那么安装就是了。

$ sudo apt-get install ruby1.8-dev
$ sudo gem install mysql

还是有问题,出现以下的错误提示:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
...
--with-mysqlclientlib
--without-mysqlclientlib

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

再次搜索一把,发现是需要安装MySQL开发环境libmysql15-dev。

$ sudo apt-get install libmysql15-dev
sudo gem install mysql

现在终于可以开始学习Rails了。

Related Posts

写了一个批量更新表中某个字段的值到另一个字段的存储过程(MySQL版)

Posted by dohkoos on June 1st, 2007 (737 views)

对blog做了一些修改,需要将entries表中的updatetime字段值替换成pubtime字段的值,写了一个MySQL的存储过程,其中涉及Cursor的使用:

DELIMITER $$;

CREATE PROCEDURE sp_batch_replace()
BEGIN
    DECLARE pId varchar(48);
    DECLARE pPubtime datetime;
    DECLARE pDone bool;
    DECLARE pCurosr CURSOR FOR SELECT id, pubtime FROM entries;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET pDone = true;

    OPEN pCurosr;
        REPEAT
            FETCH pCurosr INTO pId, pPubtime;
            UPDATE entries SET updatetime = pPubtime WHERE id = pId;
            UNTIL pDone = true
        END REPEAT;
    CLOSE pCurosr;
END$$

DELIMITER ;$$

第一次在SQLyog中写存储过程,在修改了存储过程后竟然不知道如何保存。点击File -> Save却是保存为另外一个文件,而不是直接保存修改的存储过程。经过多番尝试后发现按F5键就可以了。

Related Posts

People who read this, also read...

Cannot delete or update a parent row: a foreign key constraint fails

Posted by dohkoos on May 17th, 2007 (1,652 views)

在SQLyog中Import Data或Empty Table (Shitf + D)时,出现

Error No. 1451
Cannot delete or update a parent row: a foreign key constraint fails (...)

这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况

SET FOREIGN_KEY_CHECKS = 0;

参考资料:
Setting FOREIGN_KEY_CHECKS to 0 can also be useful for ignoring foreign key constraints during LOAD DATA and ALTER TABLE operations.

Related Posts

People who read this, also read...

MySQL数据库备份脚本(JSP版本)

Posted by dohkoos on April 8th, 2007 (910 views)

最近需要备份blog所在服务器上的mysql数据库到本机,作为虚拟主机用户,所以不能使用mysql自带的mysqldump和mysqlimport工具。因此一开始采用直接备份mysql的data目录的办法,但由于编码不同的原因产生了一些问题。在网上找到的一些备份工具都是用PHP写的,因此用JSP写了一个的备份mysql数据库的小工具。

该程序需要设置数据库连接参数和备份文件路径,运行后会自动生成一个指定的备份文件。

源码下载

Related Posts

People who read this, also read...

安装JPetStore-4.0.5时配置MySQL数据库驱动遇到的问题

Posted by dohkoos on March 10th, 2005 (645 views)

在配置JPetStore-4.0.5 时出了一点问题,特写此blog说明一下我碰到的问题。

按照教程配置好后运行 tomcat,在点击“Enter the Store”时出现了HTTP 500 的问题。从console 打印的异常记录(SimpleDataSource: Error while loading properties. Cause: java.lang.ClassNotFoundException: driver)来看是没有找到MySQL 的驱动程序。可是我已经把驱动程序copy 到WEB-INF/lib 目录下了啊!

查看sql-xml-config.xml 文件中dataSource 的属性,发现它们的值如下:
<transactionManager type="JDBC">
    <dataSource type="SIMPLE">
        <property value="${driver}" name="JDBC.Driver" />
        <property value="${url}" name="JDBC.ConnectionURL" />
        <property value="${username}" name="JDBC.Username" />
        <property value="${password}" name="JDBC.Password" />
        <property value="15" name="Pool.MaximumActiveConnections" />
        <property value="15" name="Pool.MaximumIdleConnections" />
        <property value="1000" name="Pool.MaximumWait" />
      </dataSource>
</transactionManager>

而在database.properties 中的是:
SimpleDriver=org.gjt.mm.mysql.Driver
SimpleUrl=jdbc:mysql://localhost:3306/jpetstore
SimpleUsername=jpetstore
SimplePassword=ibatis9977
因为dataSource 中的属性值是从database.properties 文件中读入的,所以要将database.properties 中的蓝色文字改成sql-xml-config.xml 文件中的红色文字。这样就不会在出现找不到driver 的异常了。

改写后的database.properties 文件内容如下:
driver=org.gjt.mm.mysql.Driver
url=jdbc:mysql://localhost:3306/jpetstore
username=jpetstore
password=ibatis9977

Related Posts

People who read this, also read...