ERROR 1130 (HY000): Host 'test177' is not allowed to connect to this MySQL server

浅浅的花香味﹌ 2023-08-17 16:16 246阅读 0赞

异常

在测试环境新搭建的MySQL服务端,启动后登陆MySQL如下异常:

  1. [root@test177 ~]# mysql -u root -po2jSLWw0ni -h test177
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. ERROR 1130 (HY000): Host 'test177' is not allowed to connect to this MySQL server

由于不能改变hostname,所以只能通过跳过数据库权限验证,来修改权限。

首先停止MySQL服务端

  1. systemctl stop mysqld

/etc/my.cnf中的[mysqld]选项中添加跳过验证策略skip-grant-tables,my.cnf文件内容如下:

  1. # For advice on how to change settings please see
  2. # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
  3. [mysqld]
  4. #
  5. # Remove leading # and set to the amount of RAM for the most important data
  6. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
  7. # innodb_buffer_pool_size = 128M
  8. #
  9. # Remove leading # to turn on a very important data integrity option: logging
  10. # changes to the binary log between backups.
  11. # log_bin
  12. #
  13. # Remove leading # to set options mainly useful for reporting servers.
  14. # The server defaults are faster for transactions and fast SELECTs.
  15. # Adjust sizes as needed, experiment to find the optimal values.
  16. # join_buffer_size = 128M
  17. # sort_buffer_size = 2M
  18. # read_rnd_buffer_size = 2M
  19. datadir=/var/lib/mysql
  20. socket=/var/lib/mysql/mysql.sock
  21. # Disabling symbolic-links is recommended to prevent assorted security risks
  22. symbolic-links=0
  23. log-error=/var/log/mysqld.log
  24. pid-file=/var/run/mysqld/mysqld.pid
  25. skip-grant-tables

然后重新启动MySQL服务:

  1. systemctl start mysqld

登陆数据库,通过以下两种方法修改权限:

通过表修改

  1. use mysql;
  2. update user set host = '%' where user = 'root' and host='localhost';
  3. select host, user from user;

通过授权

  1. GRANT ALL PRIVILEGES ON *.* TO 'account_name'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
  2. FLUSH PRIVILEGES;

转载于:https://www.cnblogs.com/linga/p/11457972.html

发表评论

表情:
评论列表 (有 0 条评论,246人围观)

还没有评论,来说两句吧...

相关阅读