#author("2024-11-04T11:30:26+08:00","default:Admin","Admin") #author("2024-11-04T11:31:41+08:00","default:Admin","Admin") [[MySQL]] リモート接続可能にする * Mysql 版本小于8.0 [#e61a75aa] mysqlにログインする #codeprettify{{ mysql -u root -p //Port指定 mysql -u root -P3307 -p use mysql; --データベースを選択 }} #codeprettify{{ grant all privileges on zhd.* to 'root'@'%' identified by 'password'; flush privileges; }} 以下のように、%のデータがあればOK #codeprettify{{ select host,user,password from user; +--------------+------+-------------------------------------------+ | host | user | password | +--------------+------+-------------------------------------------+ | localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | % | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | +--------------+------+-------------------------------------------+ }} * Mysql 8.0 [#m86e91d6] Mysql 8.0里面上的命令发生了改变 mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; You are not allowed to create a user with GRANT; 报错得原因,产生用户不能授权的原因是mysql 数据库中user 表中的特定用户(root) 的host 的属性值为localhost. 解决办法如下 #codeprettify{{ # 使用mysql数据库 use mysql; # 查看用户及权限 select user,host from mysql.user; # 更新root用户的host属性为% update user set host='%' where user='root'; # 刷新下权限 FLUSH PRIVILEGES; # 再执行就可以了,就可以使用navicat连接了 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; }} * Troubleshooting [#o6d86619] ** Public Key Retrieval is not allowed [#tc4b0741] 需要在连接数据库的 URL 中添加下面的参数 allowPublicKeyRetrieval=true #hr(); コメント: #comment_kcaptcha