1.远程连接命令
1 | #-p 后加密码是明文输入,-p后不加密码直接回车,则是密文输入 |
2.添加新用户
(1).添加新用户并设置IP访问段
只允许本地IP访问
1 | create user 'test'@'localhost' identified by '123456'; |
text为创建的账户名,123456为账户密码。
允许外网IP访问
1 | create user 'test'@'%' identified by '123456'; |
%表示允许所有IP,也可以设置指定IP访问。
刷新授权
1 | flush privileges; |
(2).为用户创建数据库
1 | create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci; |
(3).为用户分配权限
授予用户通过外网IP操作该数据库的所有去权限
1 | grant all privileges on `testdb`.* to 'test'@'%' identified by '123456'; |
授予用户通过外网IP操作所有数据库的权限
1 | grant all privileges on *.* to 'test'@'%' identified by '123456'; |
刷新授权
1 | flush privileges; |
转载请注明出处,阅读有风险,参考需谨慎!