Archive for the ‘MySQL’ Category

  1. Hello, Connector/NET World!

    Posted on 4月 1st, 2013 by cx20

    Connector/NET

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は C# による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(C# + Connector/NET + MySQL)

    using System;
    using MySql.Data.MySqlClient;
     
    class Hello
    {
        static void Main( String[] args )
        {
            string conStr = "server=localhost;user id=root;password=P@ssW0rd";
            string sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message";
     
            MySqlConnection con = new MySqlConnection(conStr);
            MySqlCommand  cmd = new MySqlCommand(sqlStr, con);
            con.Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            while( reader.Read() )
            {
                Console.WriteLine( reader.GetName(0) );
                Console.WriteLine( "---------------------" );
                Console.WriteLine( reader[0] );
            }
            reader.Close();
            con.Close();
        }
    }

    コンパイル方法

    C:¥> csc /r:MySql.Data.dll Hello.cs

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  2. Hello, MySQL World!

    Posted on 3月 4th, 2012 by cx20

    MySQL

    MySQL はオープンソースの DBMS である。LAMP(Linux、Apache、MySQL、PHP/Perl/Python)開発におけるデータベースとしても有名。
    ストレージの形式として ISAM 形式の MyISAM やトランザクションをサポートした InnoDB 形式が使用できる。
    開発当初は MySQL AB が行っていたが、Sun に買収された後、現在、Oracle が権利を所有している。

    ソースコード

    SELECT 'Hello, MySQL World!' AS Message

    実行方法(入力ファイルをリダイレクト指定した場合)

    $ mysql -t < hello.sql

    実行方法(source コマンドを使用した場合)

    $ mysql -e "source hello.sql"

    実行結果

    +---------------------+
    | Message             |
    +---------------------+
    | Hello, MySQL World! |
    +---------------------+