登录本地用户
mysql -u root -p
登录外网用户(需要注意服务器可能只允许本地登录,需要修改响应的配置文件)
mysql -u root -h 123.456.789.852 -p
添加用户
允许本地访问的用户(127.0.0.1)
create user root@localhost identified by ‘123456‘;
允许外网IP访问的用户
create user ‘root‘@‘%‘ identified by ‘123456‘;
用户分配权限
授予用户在本地服务器对该数据库的全部权限
grant all privileges on dbname.* to root@localhost identified by ‘123456‘;
授予用户通过外网IP对于该数据库的全部权限
grant all privileges on dbname.* to ‘root‘@‘%‘ identified by ‘123456‘;
刷新权限
flush privileges;