ubuntuでインストール
sudo apt install mysql-server
パスワード初期化など
sudo mysql-secure-installation
ログイン
sudo mysql -u root -p
sudoが必要なので注意
ユーザー作成
create user 'tomoya'@'localhost' identified by 'Password1!';
create user 'tomoya'@'%' identified by 'Password1!';
権限付与
grant all on *.* to 'tomoya'@'localhost' with grant option;
grant all on *.* to 'tomoya'@'%' with grant option;
allはすべての権限を意味している。はじめの*
はデータベース、次の*
はテーブルを意味している。
%
は外部サーバーからの権限行使の許可を意味している。
認証プラグインの確認
select user,host,plugin from mysql.user;
デフォルトで認証プラグインはcaching_sha2_password
になっているので変更する
認証プラグインの変更
alter user 'tomoya'@'localhost' identified with mysql_native_password by 'Password1!';
alter user 'tomoya'@'%' identified with mysql_native_password by 'Password1!';