1. 程式人生 > >1.Mysql 設定密碼,IP訪問許可權

1.Mysql 設定密碼,IP訪問許可權

1.免密碼登入

service mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  //忘記密碼,設定免密登入
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

2.設定許可權

如修改root 設定:root host 183.xx. 只能這個外網IP可以訪問

mysql> select user,host from user;
+---------------+----------------+
| user          | host           |
+---------------+----------------+
| root          | 183.62.178.193 |
| mysql.session | localhost      |
| mysql.sys     | localhost      |
| root          | localhost      |
+---------------+----------------+

設定可以任何主機IP訪問: %

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;
flush privileges;