[user]$ mysql -u root -p
DB > use mysql; # データベース mysql へ移動
DB > grant 権限,権限,... on データベース名.テーブル名 to
ユーザー名@ホスト名 identified by 'パスワード' with grant option;
*.* (全データベースの全テーブル)
DB名.* (DB名の全テーブル)
@ホスト名 を省略すると、全ホストからアクセス可能
with grant option (他のユーザーの権限変更)
管理ユーザー作成
DB > grant all(全権限)on *.* to
ユーザー名@ホスト名 identified by 'パスワード' with grant option;
一般ユーザー作成
DB > grant select,insert,update,delete,create,drop,alter,index
on *.* to ユーザー名@ホスト名 identified by 'パスワード';
・ユーザー削除
DB > drop user ユーザー名@ホスト名;
・ユーザー一覧
DB > select user,host from user;
・パスワード変更
自分自身
DB > set password = password( 'パスワード' );
他のユーザー
DB > set password for ユーザー名@ホスト名 = password( 'パスワード' );
・権限の付与/剥奪
付与
DB > grant 権限,権限,... on データベース名.テーブル名 to ユーザー名@ホスト名;
剥奪
DB > revoke 権限,権限,... on データベース名.テーブル名 from ユーザ名@ホスト名;
確認
DB > show grants for ユーザー名@ホスト名;
・root のパスワードを忘れた場合
MariaDB 停止
[root]# kill `cat /usr/local/mysql/data/ドメイン名.pid`
MariaDB をリモート接続禁止で起動
[root]# /usr/local/mysql/bin/mysqld_safe
--defaults-file=/etc/my.cnf --skip-networking --skip-grant-tables &
パスワード設定
[root]# /usr/local/mysql/bin/mysql --user=root
DB > update mysql.user set password = password( 'パスワード' ) where user = 'root';
DB > flush privileges;
DB > exit
MariaDB 再起動