‘コマンドプロンプト’ タグのついている投稿

コマンドプロンプトからMySQLのデータを修正する場合

2009 年 3 月 13 日 金曜日

フィールド名と属性を変更する
型:alter table テーブル名 change 旧フィールド名 新フィールド名 型;
例:alter table tablename change fieldname1 fildname2 char(255);

フィールドの属性のみ変更する
型:alter table テーブル名 modify フィールド名 新しい属性;
例:alter table tablename modify fieldname1 char(255);

フィールドの追加
型:alter table テーブル名 add フィールド名 属性;
例:alter table tablename add fieldnamex int;

テーブルの削除
型:drop table テーブル名;
例:drop table tablename;

レコードの作成
型:insert into テーブル名 values ('文字列の場合',数字の場合,…);
例:insert into tablename values ('MySQL',255);
※フィールドの数分入力しないと ERROR 1136 (21S01): Column count doesn't match value count at row 1のように表示される。

レコード挿入1
型:select * from テーブル名;
例:select * from tablename;

レコード挿入2
型:insert into テーブル名 (フィールド名,…) values (フィールド名の値,…);
例:insert into tablename (MySQL) values (5.0);
※入力のないフィールド部分はNULLが挿入される。

特定のフィールドだけ表示
型:select フィールド名 from テーブル名;
例:select fieldname,… from tablename;

複数の条件検索
型:select * from テーブル名 where フィールド名 検索条件 and フィールド名 検索条件
例:select * from tablename where fieldname1 like '%文字列%' and filedname2 > 数値;
※フィールド1の中で文字列から始まり、且つ、フィールド2の中で 数値より大きい

型:select * from テーブル名 where フィールド名 検索条件 or フィールド名 検索条件
例:select * from tablename where fieldname1 like '%文字列%' or filedname2 > 数値;
※フィールド1の中で文字列から始まり、又は、フィールド2の中で 数値より大きい

このエントリーを含むはてなブックマーク

xampp&コマンドプロンプトからMySQLを操作する基本フロー

2009 年 3 月 13 日 金曜日
  1. cd C:\xampp\mysql\bin
  2. mysql -u root -p
  3. パスワードを入力
  4. create databese 任意の名前(以下例としてdbnameとする); ※データベースを作成
  5. show databases; ※データベースの作成を確認
  6. use dbname; ※Databese changedが返答
  7. create table tablename(fieldname1 char(), fieldname2 char(), field3 int) ※tablename…任意
  8. show tables; ※テーブル名を確認する
  9. show fields from テーブル名;
  10. quit

行:レコード
列:フィールド

このエントリーを含むはてなブックマーク

xamppのインストール後にコマンドプロンプトからmysqlのpasswordを設定

2009 年 3 月 13 日 金曜日

参考書はset password for root=password('任意のパスワード');と記載されている事が多いが、xamppの場合、ERROR 1133 (42000): Can't find any matching row in the user tableと表示される場合がある。

そこでset password for root@localhost=password('任意のパスワード');とする事でQuery OK, …と表示される。

このエントリーを含むはてなブックマーク

xamppをインストール後にコマンドプロンプトからmysqlを実行する

2009 年 3 月 12 日 木曜日

xamppの場合phpMyAdminがインストールされるので、コマンドプロンプトを用いる必要性はほとんどないが、一般的な参考書や古いphpやMySQLの参考書はapachのインストール、phpのインストール、MySQLのインストールという手順を踏んでいるので、少し悩む初心者も多いが、xamppの場合はパスが若干異なる程度で、最新のapachやphp,mysqlのインストールに悩む場合、xamppを導入して互換をとればいよい。(互換という程のものではないが…

一般参考書
C:\mysql\bin

xampp
C:\xampp\mysql\bin

なお、windowsコマンドプロンプトでlinuxで使うlsの相当するコマンドはdir

C:\xampp\mysql\binに移動しmysqlと実行すると
mysql>
と表示される。

このエントリーを含むはてなブックマーク