Centos7中 mysql5.7 用户 创建 、授权、远程登录

摘要:
1、添加用户跟以往版本不同,MySQL5.7mysql.user表没有password字段,这个字段改成了authentication_string;这里我们使用命令进行创建用户:CREATEUSER'username'@'host'IDENTIFIEDBY'password';如创建一个test用户,密码为test123,可以进行远程登录:createuser'test'@'%'identifi

1、添加用户
跟以往版本不同,MySQL5.7 mysql.user表没有password字段,这个字段改成了 authentication_string;
这里我们使用命令进行创建用户:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

如创建一个test用户,密码为test123,可以进行远程登录:

create user 'test'@'%' identified by 'test123'

username - 你将创建的用户名,
host - 指定该用户在哪个主机上可以登陆,此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录,如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录;也可以指定某台机器可以远程登录;
password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器。

2、删除用户
如果用户创建错了,肯定要支持删除操作,使用命令:

DROP USER 'username'@'host';

3、授权
授权test用户有testDB数据库的某一部分权限:

grant select,update on testDB.* to test@'%' identified by 'test123';

授权test用户有testDB数据库的所有操作权限:

grant all privileges on testDB.* to 'test'@'%' identified by 'test123';

授权test用户拥有所有数据库的某些权限:

grant select,delete,update,create,drop on *.* to 'test'@'%' identified by 'test123';

privileges - 用户的操作权限,如select,delete,update,create,drop等(详细列表可自行百度),如果要授予所有的权限可使用all(参考第二种授权方式);% 表示对所有非本地主机授权,不包括localhost。

案例:

GRANT ALL privileges ON test.* TO usr@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;  #设置密码时要三种字符并存

Query OK, 0 rows affected, 1 warning (0.01 sec)

flush privileges;  #刷新表权限

Query OK, 0 rows affected (0.01 sec)

 mysql -ugeek -p

Enter password:

ERROR 1045 (28000): Access denied for user 'geek'@'localhost' (using password: YES)#报错是说在geek用户在本地登录需要密码,而我刚刚没设置本地登录,所以进入root设置

[root@instance-ozyu8y37 ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 1261

Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> GRANT ALL privileges ON test.* TO usr@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

退出,重新用新创建的用户登录就成功了​

免责声明:文章转载自《Centos7中 mysql5.7 用户 创建 、授权、远程登录》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C#中生成随机数的几种方法python使用zipfile解压文件中文乱码问题下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

oracle 11g创建数据库教程

cd /oracle/app/oracle/product/11.2.0/dbhome_1/bin ./dbca 自定义用户表空间大小。 安装过程半个小时是需要的。 2.配置oracle系统用户环境变量 使用vi等文本编缉器在~/.bash_profile中追加以下内容。 不要使用cat来添加,因为cat会将全部变量替换为当前值...

java安全沙箱(四)之安全管理器及Java API

java是一种类型安全的语言,它有四类称为安全沙箱机制的安全机制来保证语言的安全性,这四类安全沙箱分别是: 类加载体系 .class文件检验器 内置于Java虚拟机(及语言)的安全特性 安全管理器及Java API 本篇博客主要介绍“类安全管理器及Java API”的基本原理,如需了解其它几类安全机制可以通过上面的博客链接进入查看。 简介 java安全...

mysql用root用户给其他用户授权报错1044 access denied for user root

公司本地测试数据库一直使用root直接使用数据库,一直使用没问题 突然有一天,需要增加一个用户,并使用该用户进行操作数据库 在成功创建新用户后,开始想给用户授予最高权限,结果报错,1044 access denied for user root 我以为是无法创建同样的root用户 于是建了一个新数据库,newdb ,单独个新建用户增加newdb的权限,还是...

pm grant 命令

CustomLocale.apk所需要的权限"android.permission.CHANGE_CONFIGURATION"自Android 4.2,4.2.2起系统定义为android:protectionLevel="signature|system|development",这就需要在已root的android设置上运行命令: adb shell...

oracle创建用户、授予权限及删除用户

创建用户 oracle对表空间 USERS 无权限 alter user 用户名 quota unlimited on users; //创建临时表空间 create temporary tablespace test_temp tempfile 'E:/oracle/product/10.2.0/oradata/testserver/test_tem...

hive权限配置

基于CDH5.x的Hive权限配置 1、打开权限控制,默认是没有限制的 set hive.security.authorization.enabled=true; 2、配置默认权限 1 hive.security.authorization.createtable.owner.grants = ALL 2 hive.security.authoriz...