日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發(fā)布時間:2023/12/10 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql5.7 新建远程用户_Centos7中 mysql5.7 用户 创建 、授权、远程登录 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1、添加用戶

跟以往版本不同,MySQL5.7 mysql.user表沒有password字段,這個字段改成了 authentication_string;

這里我們使用命令進行創(chuàng)建用戶:

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

如創(chuàng)建一個test用戶,密碼為test123,可以進行遠程登錄:

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

username - 你將創(chuàng)建的用戶名,

host - 指定該用戶在哪個主機上可以登陸,此處的"localhost",是指該用戶只能在本地登錄,不能在另外一臺機器上遠程登錄,如果想遠程登錄的話,將"localhost"改為"%",表示在任何一臺電腦上都可以登錄;也可以指定某臺機器可以遠程登錄;

password - 該用戶的登陸密碼,密碼可以為空,如果為空則該用戶可以不需要密碼登陸服務器。

2、刪除用戶

如果用戶創(chuàng)建錯了,肯定要支持刪除操作,使用命令:

DROP USER 'username'@'host';

3、授權

授權test用戶有testDB數(shù)據庫的某一部分權限:

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

授權test用戶有testDB數(shù)據庫的所有操作權限:

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

授權test用戶擁有所有數(shù)據庫的某些權限:

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)

退出,重新用新創(chuàng)建的用戶登錄就成功了?

總結

以上是生活随笔為你收集整理的mysql5.7 新建远程用户_Centos7中 mysql5.7 用户 创建 、授权、远程登录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。