用SET PASSWORD命令
首先登录MySQL。
格式:mysql> set password for 用户名@localhost = password('新密码');
例子:mysql> set password for root@localhost = password('123');
添加用户
1.允许本地访问的用户(127.0.0.1)
create user zhrt@localhost identified by '123456';
2.允许外网IP访问的用户
create user 'zhrt'@'%' identified by '123456';
查看用户
select user,host from mysql.user;
用户分配权限
授予用户在本地服务器对该数据库的全部权限
grant all privileges on dbname.* to zhrt@localhost identified by '123456';
授予用户通过外网IP对于该数据库的全部权限
grant all privileges on dbname.* to 'zhrt'@'%' identified by '123456';