mysql添加用户

Posted 76 months ago mysql

# mysql -u root -p
# 允许本地 IP 访问 localhost, 127.0.0.1
# insert into mysql.user(Host,User,Password) 
values('localhost','zhouz',password('1234'));
# 允许外网 IP 访问
# insert into mysql.user(Host,User,Password) 
values('%','zhouz',password('1234'));
# 刷新授权
# flush privileges;
# 创建数据库
# create database zhouzdb DEFAULT CHARSET 
utf8 COLLATE utf8_general_ci;
# 授予用户通过外网IP对于该数据库的全部权限
# grant all privileges on `zhouzdb`.* to 
'zhouz'@'%' identified by '1234';
# 授予用户在本地服务器对该数据库的全部权限
# grant all privileges on `zhouzdb`.* to
 'zhouz'@'localhost' identified by '1234';

 
# 刷新权限
# flush privileges;
# 退出 root 重新登录
# \q
# 已新帐号 zhouz 登录,由于使用的是 % 任意IP连接,所以需要指定外部访问IP
# mysql -u zhouz -h 192.168.1.168 -p
# 1234

utf8mb4

创建用户
CREATE USER free@'%' IDENTIFIED  BY '密码'
创建数据库
create database free DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
给数据库加权限
GRANT ALL PRIVILEGES ON `free`.* TO free@'%';
给用户加全县
GRANT ALL PRIVILEGES ON *.* TO 'finley'@'%' WITH GRANT OPTION;

点击评论