今天在测试docker时,因更换为Mysql8,使用SQL方式实现远程授权,其方式方法同于Mysql,但语句稍有不同,仅供参考。
登录mysql
            
            
              shell
              
              
            
          
          mysql -u root -p
输入密码: [请依据交互输入你的mysql密码]
        切换数据库
            
            
              shell
              
              
            
          
          use mysql;
        选择需要查看的信息
            
            
              shell
              
              
            
          
          select host, user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
        直接给指定用户授权
            
            
              shell
              
              
            
          
          update user set host='%' where user='root';
grant all privileges on *.* to 'root'@'%';
flush privileges;
grant all on *.* to 'root'@'%';
flush privileges;
        创建新用户并授权
            
            
              shell
              
              
            
          
          create user 'root'@'%' identified by 'YourPassword';
grant all privileges on *.* to 'root'@'%';
flush privileges;
grant all on *.* to 'root'@'%';
flush privileges;