MySQL とは, オープンソースのリレーショナルデータベース管理システムである. MySQL のインストールとテスト実行を行ないます
既定(デフォルト)のキャラクタセット: cp932またはutf8
以下「Ubuntu Linux」を選んだとして説明を続ける.
以下「Ubuntu Linux 20.04 (x86, 64-bit)」を選んだとして説明を続ける.
すでに「サインアップ」済みなら, 「ログイン」を選び, 電子メールアドレス(Email)と, パスワード(Password)を入力.
まだ「サインアップ」していないのなら, 「サインアップ」を選ぶ, 電子メールアドレスとパスワードを登録する.
tar -xvf mysql-server_8.0.21-1ubuntu20.04_amd64.deb-bundle.tar
sudo apt -yV install ./mysql-client_8.0.21-1ubuntu20.04_amd64.deb ./mysql-community-client_8.0.21-1ubuntu20.04_amd64.deb ./mysql-community-client-core_8.0.21-1ubuntu20.04_amd64.deb ./mysql-common_8.0.21-1ubuntu20.04_amd64.deb sudo apt -yV install ./mysql-server_8.0.21-1ubuntu20.04_amd64.deb ./mysql-community-server_8.0.21-1ubuntu20.04_amd64.deb ./mysql-community-server-core_8.0.21-1ubuntu20.04_amd64.deb
同じものを 2回入れる.
次のコマンドで確認できる.
sudo cat /etc/passwd | grep postgres
※ 「x」は no password という意味(パスワードがないという意味ではない)
このアカウントは Linux が管理するアカウントのこと.MySQL が管理するアカウントとは別のものである.
データベースファイルを置くディレクトリのこと.
/var/lib/mysql になる.「sudo ls -la /var/lib/mysql」で確認できる.
mysqladmin -u root -p version
パスワードは,英文字,数字,記号を使う.日本語は使わない.
パスワードを新規に設定する場合は,次のように操作.
mysqladmin --user=root password "(新しいパスワード)"
すでにパスワードを設定済みで,変更をしたい場合は,次のように操作.
mysqladmin --user=root --password=(古いパスワード) password "(新しいパスワード)"
データベースを作成するために,SQL の create database コマンドを使用する.
「root」は MySQL データベース管理者のユーザ名
mysql -u root -p
プロンプトが出るので, ここでは,MySQL データベース管理者のパスワードを入れる.
画面にパスワードが表示されないのは正常動作.
実行後,エラーメッセージが出ないことを確認
utf8 の場合の生成例
create database testdb default character set utf8 collate utf8_unicode_ci;
cp932 の場合の生成例
create database testdb default character set cp932 collate cp932_japanese_ci;
show databases;
\quit
「root」は MySQL データベース管理者のユーザ名, 「testdb」はデータベース名.
mysql -u root -p -D testdb
プロンプトが出るので, ここでは,MySQL データベース管理者のパスワードを入れる.
画面にパスワードが表示されないのは正常動作.
実行後,エラーメッセージが出ないことを確認
create table order_records (
id integer primary key not null,
year integer not null CHECK ( year > 2008 ),
month integer not null CHECK ( month >= 1 AND month <= 12 ),
day integer not null CHECK ( day >= 1 AND day <= 31 ),
customer_name text not null,
product_name text not null,
unit_price real not null check ( unit_price > 0 ),
qty integer not null default 1 check ( qty > 0 ),
created_at timestamp not null default current_timestamp,
updated_at timestamp not null default current_timestamp on update current_timestamp,
check ( ( unit_price * qty ) < 200000 ) );
start transaction; insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 1, 2020, 7, 26, 'kaneko', 'orange A', 1.2, 10 ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 2, 2020, 7, 26, 'miyamoto', 'Apple M', 2.5, 2 ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty) values( 3, 2020, 7, 27, 'kaneko', 'orange B', 1.2, 8 ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price) values( 4, 2020, 7, 28, 'miyamoto', 'Apple L', 3 ); commit;
select * from order_records;
start transaction; update order_records set unit_price = 11.2 where id = 1; commit; select * from order_records;
show tables;
\quit
本サイトは金子邦彦研究室のWebページです.サイトマップは,サイトマップのページをご覧下さい. 本サイト内の検索は,サイト内検索のページをご利用下さい.
問い合わせ先: 金子邦彦(かねこ くにひこ) ![]()