0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQL5.7での初期ユーザー設定

Posted at

忘れるのでメモ
ルートパスワードを好きなものに変更するバッチ。
パスワードの強度は最低にする。root/rootでもOK。なので、使用は注意。

# !/bin/bash

MYROOTPASSWORD='password'

DEFAULT_PASSWORD=`cat /var/log/mysqld.log | grep "temporary password" | awk '{print $11}'`
mysql -u root -p${DEFAULT_PASSWORD} --connect-expired-password -e "SET GLOBAL validate_password_length=4;"
mysql -u root -p${DEFAULT_PASSWORD} --connect-expired-password -e "SET GLOBAL validate_password_policy=LOW;"
mysql -u root -p${DEFAULT_PASSWORD} --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYROOTPASSWORD}';"

サブアカウントを作るバッチ。

# !/bin/bash
MYROOTPASSWORD='password'
MYSECONDUSER='root2'
MYSECONDPASSWORD='password2'

mysql -u root -p${MYROOTPASSWORD} -e "SET GLOBAL validate_password_length=4;"
mysql -u root -p${MYROOTPASSWORD} -e "SET GLOBAL validate_password_policy=LOW;"
mysql -u root -p${MYROOTPASSWORD} -e "create user ${MYSECONDUSER}@localhost identified by '${MYSECONDPASSWORD}';"
mysql -u root -p${MYROOTPASSWORD} -e "grant all on *.* to ${MYSECONDUSER}@localhost identified by '${MYSECONDPASSWORD}';"
mysql -u root -p${MYROOTPASSWORD} -e "grant all on *.* to ${MYSECONDUSER}@'%' identified by '${MYSECONDPASSWORD}';"
mysql -u root -p${MYROOTPASSWORD} -e "flush PRIVILEGES;"
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?