Mysql初期設定

# インストール直後に実行 # mysql_secure_installation 以下の様なエラーが出た場合 -- # mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) -- # パスワードを忘れた場合の手順参考 https://liginc.co.jp/web/programming/mysql/87393 $ service mysql stop $ mysqld_safe --skip-grant-tables & $ mysql -u root $ use mysql; $ update user set password=PASSWORD("root") where User='root'; $ flush privileges; $ quit $ service mysqld stop $ service mysqld start -- ユーザー追加 $ create USER yugeta; xxx $ create user 'yugeta'@'localhost' identified by '%myPassWord%'; 登録したユーザーの確認 $ use mysql; $ select * from user; または、 $ select User,Host from mysql.user; -- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 上記エラーが出たら -- ユーザーの削除方法 $ REVOKE ALL PRIVILEGES, GRANT OPTION FROM '%user'@'localhost'; $ DELETE FROM mysql.user WHERE user='%user' and host='localhost'; $ FLUSH PRIVILEGES; または $ DROP USER %user@localhost; -- 権限の確認 > show grants for 'yugeta'@'localhost'; -- 全権限付与 $ grant all privileges on *.* to '%user'@'localhost';