MySQL MariaDB密碼以及遠程訪問權限配置

環境
MySQL 版本 Server version: 5.5.64-MariaDB MariaDB Server
Linux版本  CentOS Linux release 7.6.1810 (AltArch)mysql


操做
1)root默認狀況下無須密碼登錄,直接回車,要求輸入密碼,直接回車
root@host-172-16-61-102 bin]# mysql -uroot -p
PASSWORD:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.64-MariaDB MariaDB Serversql

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.數據庫

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.服務器


2)選擇數據庫,不然執行指令出錯No database selected
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -Atcp

Database changedide


3)指定root用戶的密碼是root
MariaDB [mysql]> update user set password=password("root")where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5  Changed: 0  Warnings: 0
注意:
執行無效狀況下,多是版本的問題,查看是不是password字段仍是authentication_string字段保存密碼
update user set password = password("root"),authentication_string=password("root") where user=root;
經過指令desc user 能夠查看當前user的表結構ui


4)授予訪問權限
root用戶使用密碼從任何主機鏈接到mysql服務器
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
其中BY後面是root用戶的密碼:rootthis

只容許192.168.10.168經過root用戶鏈接到mysql服務器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.10.168' IDENTIFIED BY 'root' WITH GRANT OPTION;orm


5)刷新權限
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)get

注意:1)Navicat遠程登錄失敗1045 - Access denied for user 'root@192.168.63.184' (using password: YES)授予訪問權限沒有執行,執行第四步可經過指令 select host,user from user;查看是否有遠程訪問的權限2)關閉防火牆systemctl stop firewalld.service            #中止firewallsystemctl disable firewalld.service        #禁止firewall開機啓動開啓端口firewall-cmd --zone=public --add-port=3306/tcp --permanentmysql服務啓動,能夠經過lsof -i:3306端口是否監聽重啓防火牆firewall-cmd --reload

相關文章
相關標籤/搜索