環境

Machine Env / FW Last Updated
Windows SQL Server 2022 Developer 16.0.4200.1 2025/07/09
  - SQL Server Management Studio 21.4.8 2025/07/14
  PostgreSQL 17.2 2024/12/31
  MongoDB 8.1.1 2025/07/02
  - Mongosh 2.5.1 2025/05/14
  - Mongodump 2024/10/19
  MySQL Community Server 8.4.2 2024/08/24
Windows Insider PostgreSQL 17.5 2025/05/17
  MySQL Community Server 9.1.0 2025/01/04
Chrome OS Flex PostgreSQL 17.5 2025/05/17

ノウハウ

データベース全般

MongoDB

  • インストール
    1. Scoopのインストール
      Set-ExecutionPolicy RemoteSigned -scope CurrentUser
      iex (new-object net.webclient).downloadstring('https://get.scoop.sh') 
      
    2. MongoDBのインストール
      scoop install mongodb
      
    3. Mongoshのインストール
      scoop bucket add extras
      scoop install mongosh
      
    4. MongoDB起動
      mongod
      
    5. 接続文字列
      mongodb://localhost:27017
      
    6. バックアップとリストア
      • バックアップは実行時のカレントディレクトリのdumpディレクトリに作成される
      • バックアップ
        mongodump
        
      • リストア
        mongorestore
        
    7. MongoDBのアップデート
      scoop update mongodb
      
      1. 8.1.0への移行
        • 8.1では、”featureCompatibilityVersion”が8.0である必要あり
          • mongoshを起動し、下記を実行する
            db.adminCommand({ setFeatureCompatibilityVersion: "8.0" })
            
          • 一旦移行すると、戻すことができないため、下記に変更して実行する
            db.adminCommand({ setFeatureCompatibilityVersion: "8.0", confirm: true })
            
      2. 8.0 への移行
        • 8.0 で互換性を保証するバージョンは、”7.0”,”7.3”,”8.0”であるため、”featureCompatibilityVersion”はそのいずれかにしておく必要あり
          {
            "_id": "featureCompatibilityVersion",
            "version": "7.0"
          }
          
          • 今回、7.1.1から移行する際、上述の”featureCompatibilityVersion”が”7.1”となっており、8.0を起動できなかった。
  • MongoDB for VS Codeをインストールしておくとよい VSCode

SQL Server

PostgreSQL

  • PgAdmin対応表 PostgreSQL | PgAdmin4 ———–|———– 17.5 | 9.3 17.4/17.3 | 9.0 17.2 | 8.14 17.0 | 8.12 16.4 | 8.10 16.1 | 7.8 16 | 7.6
  • postgres/pgsuper
  • リリース間移行
    • 並行稼働のため、新バージョンは現行バージョンとは異なるポート番号とする(現行:5432、新:5433)
    • 現行バージョンのバックアップ
      set PGCLIENTENCODING="UTF8"
      pg_dumpall -p 5432 --username=postgres > <BackupFile>
      
    • ロケールの編集(データベース作成部分)
      • バックアップされた内容例
        CREATE DATABASE batch WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'Japanese_Japan.932';
        
      • 編集後の内容例
        CREATE DATABASE batch WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'Japanese_Japan.932' LC_CTYPE = 'Japanese_Japan.932';
        
    • 新バージョンへのリストア
      set PGCLIENTENCODING="UTF8"
      type <Edited_BackupFile> | psql -d postgres -p 5433 --username=postgres
      
  • タイムアウト時間の設定(マシン性能の問題等で、PgAdminを起動できない場合の対応)
    • サーバとの接続がタイムアウトしているため、タイムアウト時間を延ばす
  • コマンドラインでのSQL
    • psqlにPATHが設定されていないので、追加する必要あり
  • 参照専用ユーザの作成
    • データを更新することはなく、参照だけできれば良い場合 運用時のユーザや開発者向けユーザとは別に、参照専用のユーザがあると有効
    • PostgreSQL 14以降の場合、データの参照向けロールがあるので、そのロールを設定すればよい。
      >grant pg_read_all_data to <User>
      
  • PHP + Apache + PostgreSQL

MySQL

  • DDL
    • rootパスワードの変更
      mysql> ALTER USER root@localhost IDENTIFIED BY "root";
      
    • ユーザの追加およびパスワードの登録
      mysql> CREATE USER taish;
      mysql> ALTER USER taish@localhost IDENTIFIED BY "taishow";
      
    • アカウントパスワードの割り当て
  • Dumpをロードするには、local_infileをONにしておく必要あり
    SET GLOBAL local_infile = ON;
    
  • MySQL Shell for VS Code
    • VSCodeユーザ向けにもユーティリティがある! Main
    • 簡単にテーブルのデータを確認できる Show Data
  • MySQL Community Server Container
  • MySQL Community Server 8.4.2 (LTS)
    • Oracleプロファイル作成のうえ、ダウンロード
    • インストールすると、MySQL Configuratorで設定する MySQL Configurator root/mysqlsuper

    Configulation Log</summary>

    Beginning configuration step: Writing configuration file
    
    Saving my.ini configuration file...
    Saved my.ini configuration file.
    Ended configuration step: Writing configuration file
    
    Beginning configuration step: Updating Windows Firewall rules
    
    Adding a Windows Firewall rule for MySQL84 on port 3306.
    Attempting to add a Windows Firewall rule with command: netsh.exe advfirewall firewall add rule name="Port 3306" protocol=TCP localport=3306 dir=in action=allow
    Ok.
    
    
    Successfully added the Windows Firewall rule.
    Adding a Windows Firewall rule for MySQL84 on port 33060.
    Attempting to add a Windows Firewall rule with command: netsh.exe advfirewall firewall add rule name="Port 33060" protocol=TCP localport=33060 dir=in action=allow
    Ok.
    
    
    Successfully added the Windows Firewall rule.
    Ended configuration step: Updating Windows Firewall rules
    
    Beginning configuration step: Adjusting Windows service
    
    Attempting to grant the required filesystem permissions to the 'NT AUTHORITY\NetworkService' account.
    Granted permissions to the data directory.
    Granted permissions to the install directory.
    Adding new service
    New service added
    Ended configuration step: Adjusting Windows service
    
    Beginning configuration step: Initializing database (may take a long time)
    
    Attempting to run MySQL Server with --initialize-insecure option...
    Starting process for MySQL Server 8.4.2...
    Starting process with command: C:\Program Files\MySQL\MySQL Server 8.4\bin\mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.4\my.ini" --console --initialize-insecure=on --lower-case-table-names=1...
    MySQL Server Initialization - start.
    C:\Program Files\MySQL\MySQL Server 8.4\bin\mysqld.exe (mysqld 8.4.2) initializing of server in progress as process 15752
    InnoDB initialization has started.
    InnoDB initialization has ended.
    root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    MySQL Server Initialization - end.
    Process for mysqld, with ID 15752, was run successfully and exited with code 0.
    Successfully started process for MySQL Server 8.4.2.
    MySQL Server 8.4.2 intialized the database successfully.
    Ended configuration step: Initializing database (may take a long time)
    
    Beginning configuration step: Updating permissions for the data folder and related server files
    
    Attempting to update the permissions for the data folder and related server files...
    Inherited permissions have been converted to explicit permissions.
    Full control permissions granted to: NETWORK SERVICE.
    Full control permissions granted to: Administrators.
    Full control permissions granted to: CREATOR OWNER.
    Full control permissions granted to: SYSTEM.
    Access to the data directory is removed for the users group.
    Permissions for the data folder and related server files are updated correctly.
    Ended configuration step: Updating permissions for the data folder and related server files
    
    Beginning configuration step: Starting the server
    
    Attempting to start service MySQL84...
    MySQL Server - start.
    C:\Program Files\MySQL\MySQL Server 8.4\bin\mysqld.exe (mysqld 8.4.2) starting as process 13844
    InnoDB initialization has started.
    InnoDB initialization has ended.
    CA certificate ca.pem is self signed.
    Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
    X Plugin ready for connections. Bind-address: '::' port: 33060
    C:\Program Files\MySQL\MySQL Server 8.4\bin\mysqld.exe: ready for connections. Version: '8.4.2'  socket: ''  port: 3306  MySQL Community Server - GPL.
    Successfully started service MySQL84.
    Waiting until a connection to MySQL Server 8.4.2 can be established (with a maximum of 10 attempts)...
    Retry 1: Attempting to connect to Mysql@localhost:3306 with user root with no password...
    Successfully connected to MySQL Server 8.4.2.
    Ended configuration step: Starting the server
    
    Beginning configuration step: Applying security settings
    
    Attempting to update security settings.
    Updated security settings.
    Ended configuration step: Applying security settings
    
    Beginning configuration step: Updating the Start menu link
    
    Attempting to verify command-line client shortcut.
    Verified command-line client shortcut.
    Verified command-line client shortcut.
    Ended configuration step: Updating the Start menu link
    
    Beginning configuration step: Updating example databases
    
    Updating example databases...
    Ended configuration step: Updating example databases
    

    </details>

  • MySQL 8.0.28
    • ZIPファイルを任意のディレクトリに展開する
    • my.iniを展開したディレクトリに作成する
      [mysqld]
      # set basedir to your installation path
      basedir=D:\mysql-8.0.28-winx64
      # set datadir to the location of your data directory
      datadir=D:\mysql-8.0.28-winx64\data
      
    • データディレクトリを初期化する(パスワード生成せず)
      mysqld.exe --initialize-insecure --console
      
    • MySQL Server を起動する(パスワードなし)
      mysql.exe -u root --skip-password
      
    • MySQLをサービスに登録する
      D:\mysql-8.0.28-winx64\bin\mysqld --install MYSQL80
      
    • MySQLのサービスを開始する
      net start MYSQL80