sql script
バージョンの確認
select version();
テーブルの定義
show create table cities;
show columns from cities;
別テーブルのカラムの値をコピー
insert into cities2 (id,name) select id,name from cities;
グローバルレベルでCREATE権限を設定
grant create on *.* to 'scott'@'localhost';
権限を表示
show grants for scott@localhost;
ユーザーの表示
select user,host from mysql.user;
ユーザーが存在しない時にユーザーを作成
create user if not exists scott@localhost identified by 'tiger123';
カラムの追加
alter table cities add browser varchar(128) after population;
カラムの削除
alter table cities drop browser;
データの行数
select count(*) from cities;
文字コードの確認
show variables like 'char%';
文字コードの設定
set character_set_client='utf8';
文字コードの表示
SHOW CHARACTER SET;
Insert ができない時は、Update
insert into city_city set code='t3321',name='岡山aaa',population=691734,date_mod='2001-2-15' on DUPLICATE KEY UPDATE name='岡山bbb',population = 39111,date_mod='2018-4-25';
root のパスワードの設定
ALTER USER 'root'@'localhost' IDENTIFIED BY "secret";
Return
Jun/23/2020 AM 08:00