mysql4.0.17和mysql4.1.18在学习日记开源项目中使用的问题

  如果用ant初始化mysql4.0.17或mysql4.1.18,则必须用ascii编码(也就是一般的文本文件)写sql语句;如果用source命令导入数据或者用mysql < *.sql 建数据库,则必须用utf-8编码写sql语句。

  在使用mysql4.1.18,数据库前,必须设置:[client][mysqld]下的default_character_set=utf8

  用source命令导入mysql4.0.17的脚本时必须是用utf-8编码写sql语句,倒是mysql4.0.17不必在my.ini或my.cnf下设置默认字符集,就是设置了好像也不起作用?但是又好像有作用(见:我会设置mysql的默认字符集了 http://www.123go.org.cn/disDiaryContentAction.do?searchDiaryID=153&goalID=153&naviStr=a10a241)

  

  所以,我把学习日记初始化数据库的脚本分为了:learndiarydb_mysql4.0.17.sql,learndiarydb_mysql4.0.17_for_ant.sql,learndiarydb_mysql4.1.18.sql ,learndiarydb_mysql4.1.18_for_ant.sql 。

  相应的,初始化数据库的ant脚本也分为了两个target:initdb_mysql4.0.17和initdb_mysql4.1.18,在target:initdb_mysq4.0.17,必须其中指定数据库编码:url="jdbc:mysql://localhost:3306/learndiarydb?useUnicode=true&characterEncoding=UTF-8" ;而在initdb_mysql4.1.18中则不必。

  搞不懂是怎么一回事了?只能知其然而不知其所以然了,哪位过来者提示一下?:)

3 thoughts on “mysql4.0.17和mysql4.1.18在学习日记开源项目中使用的问题”

  1.   两种导入数据的mysql命令:

      1、用source命令:前提是数据库已经创建,登录mysql后,use db; 然后再用source < yourpath\db.sql;

      2、用mysql命令,不需要登录,但要在命令中use db;(且db不能加引号'或撇号`),mysql < yourpath\db.sql

      db.sql内容示例如下:

    drop database if exists `learndiarydb`;

    create database if not exists `learndiarydb`;

    use learndiarydb;

    --

    -- Table structure for table `article`

    --

    DROP TABLE IF EXISTS `article`;

    CREATE TABLE article (

      articleID smallint(5) unsigned NOT NULL auto_increment,

      typeID tinyint(1) unsigned default NULL,

      parentID smallint(5) unsigned default '0',

      articleName varchar(60) default NULL,

      articleText text,

      writeDate datetime default NULL,

      articleResource varchar(255) default NULL,

      userID smallint(5) default NULL,

      lastUpdate datetime default NULL,

      diarySize smallint(5) unsigned default '0',

      adviceSize smallint(5) unsigned default '0',

      userName varchar(12) default NULL,

      joinNum smallint(5) unsigned default '0',

      viewNum smallint(5) unsigned default '0',

      PRIMARY KEY  (articleID)

    ) TYPE=InnoDB;

      我在学习日记程序中改成了用mysql命令直接建库,导入数据,如上,这样少一个登录的步骤。

      但是在用ant脚本初始化数据库时必须先建库,不然会报相应数据库不存在的错。

      不论用ant脚本或mysql中的命令初始化数据库都必须先建用户。

  2. "learndiarydb_{databaseType}.sql" is used for creating database without test data with specified type database;

    {databaseType} equal to:mysql4.0.17,sqlserver,db2,etc..

    It is the database's installation under mysql below.

     

    Usage:("$" indicates the begin of command,on windows platform)

    1.create a new database user "dbuser" with password "1234":

      1).login mysql with root authority:

           $mysql -uroot -p

           enter your root password;

      2).create new user:

           GRANT ALL PRIVILEGES ON *.* TO dbuser@localhost  IDENTIFIED BY '1234' WITH GRANT OPTION;

    2.initializing LearnDiary's database from *.sql with mysql's batch command:

       $mysql < yourpath\learndiarydb_mysql4.0.17.sql

    3.after initializing database, there are two users existed in it, one is "admin"-administrator account, which password is "tester";

      another is "guest"-guest account, which password is "tester" too.

      

    4.export data into a *.sql file:

      $mysqldump learndiarydb > yourpath\learndiarydb_mysql4.0.17.sql

    5.note:

      1).before you initializing mysql4.1.18 database of LearnDiary,please add "default_character_set=utf8"(without ") under [client] and [mysqld] in my.ini or my.cnf,then restart your mysql;

      2).files:learndiarydb_mysql4.0.17_for_ant.sql and learndiarydb_mysql4.1.18_for_ant.sql are for the target of initializing  database of LearnDiary  with ant;

      3).before you initializing database with command "ant initdb_mysql4.0.17" or "ant initdb_mysql4.1.18",please create database "learndiarydb" with step below at first:

          1>mysqladmin create learndiarydb


  3. 1.create a new database user "dbuser" with password "1234":

      1).login mysql with root authority:

           $mysql -uroot -p

           enter your root password;

      2).create new user:

           GRANT ALL PRIVILEGES ON *.* TO dbuser@localhost  IDENTIFIED BY '1234' WITH GRANT OPTION;

    2.initializing LearnDiary's database from *.sql with mysql's batch command:

       $mysql < yourpath\learndiarydb_mysql4.0.17.sql

    需要改成:


    1.create a new database user "dbuser" with password "1234":

      1).login mysql with root authority:

           $mysql -uroot -p

           enter your root password;

      2).create new user:

           GRANT ALL PRIVILEGES ON *.* TO dbuser@localhost  IDENTIFIED BY '1234' WITH GRANT OPTION;

           GRANT ALL PRIVILEGES ON *.* TO dbuser@localhost.localdomain  IDENTIFIED BY '1234' WITH GRANT OPTION; (在Redhat linux9.0中运行不知为什么设置成localhost:8080的mysql数据库会连接localhost.localdomain?)

    2.initializing LearnDiary's database from *.sql with mysql's batch command:

       $mysql -udbuser -p < yourpath\learndiarydb_mysql4.0.17.sql

       输入dbuser的密码1234

Comments are closed.