Blogger Information
Blog 11
fans 0
comment 0
visits 16667
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Mysql添加新用户并为用户创建数据库、分配权限
提百万的博客
Original
1318 people have browsed it

登录MySQL

mysql -u root -p

添加新用户

允许本地 IP 访问 localhost, 127.0.0.1

create user 'test'@'localhost' identified by '123456';

允许外网 IP 访问

create user 'test'@'%' identified by '123456';

刷新授权

flush privileges;

为用户创建数据库

create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

为新用户分配权限

授予用户通过外网IP对于该数据库的全部权限

grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';

授予用户在本地服务器对该数据库的全部权限

grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';

刷新权限

flush privileges;

退出 root 重新登录

exit

用新帐号 test 重新登录,由于使用的是 % 任意IP连接,所以需要指定外部访问IP

mysql -u test -h <IP> -p



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post