0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DB入門・MySQLで作るじゃんけんゲーム ①DB作成

Posted at

インストール、path設定済みの方は2から

1 MySQLインストール,環境path設定

# MySQL公式サイトからダウンロード後、インストーラーを実行

# 環境変数PATHに追加(PowerShellで確認)
echo $env:PATH

# PATHにMySQLのbinディレクトリを追加
# 例: C:\Program Files\MySQL\MySQL Server 8.0\bin

2 MySQLでユーザー作成

-- MySQLにrootでログイン
mysql -u root -p

-- 新しいユーザーを作成
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

-- ユーザーに権限を付与
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';

-- 権限を反映
FLUSH PRIVILEGES;

-- 作成したユーザーを確認
SELECT User, Host FROM mysql.user WHERE User = 'myuser';

-- MySQLからログアウト
EXIT;

3 ユーザーでDBを作成

-- 作成したユーザーでログイン
mysql -u myuser -p

-- データベースを作成
CREATE DATABASE myapp_db;

-- データベース一覧を確認
SHOW DATABASES;

-- 作成したデータベースを使用
USE myapp_db;

-- 現在のデータベースを確認
SELECT DATABASE();

4 create_status_table.sqlを実行してテーブルを作成

-- SQLファイルを実行(MySQLにログインした状態で)
SOURCE /path/to/create_status_table.sql;

-- または、コマンドラインから直接実行
mysql -u myuser -p myapp_db < /path/to/create_status_table.sql
create_status_table.sql

CREATE TABLE `status` (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `pin` varchar(4) NOT NULL, 
  `winRate` int NOT NULL,
  `drawRate` int NOT NULL,
  `loseRate` int NOT NULL,
  `handCount` int NOT NULL,
  `guuRatio` int NOT NULL,
  `chokiRatio` int NOT NULL,
  `paaRatio` int NOT NULL,
  `point` int NOT NULL,
  PRIMARY KEY(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?