阿里雲服務器 ——寶塔面板配置安裝的數據庫如何進行遠程連接


首先在服務器安全組添加3306放行端口

繼而再去面板中添加3306放行端口

在阿里雲服務器中登錄mysql進行遠程配置(權限為root才能配置,否則配置不成功)

1. 先用localhost登錄
# mysql -u root -p
Enter password: 
2. 執行授權命令
mysql> grant all privileges on *.* to root@'%' identified by 'password'; 紅色底板的password自行設置
Query OK, 0 rows affected (0.07 sec)
3. 退出再試
mysql> quit
Bye
再試登錄:(這里測試用另一台主機(我這里用win10的cmd命令行連接)就能登錄,得先連網)

C:\Users\ASDS>mysql -uroot -h 主機ip -p     紅色底板的主機ip是要連接的數據庫的載體主機ip
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 5.5.61-log Source distribution

Copyright (c) 2000, 2017, 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>

登錄成功

第二種授權方式:

先在服務器數據庫中創建一個用戶和密碼:

mysql> create user geek identified by 'password';
Query OK, 0 rows affected (0.00 sec)

執行授權連接單獨的一個數據庫,我這里連接test數據庫:

mysql> grant all privileges on test.* to geek@'%';
Query OK, 0 rows affected (0.00 sec)

 登錄測試

C:\Users\ASDS>mysql -ugeek -h 128.10.2.64 -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.61-log Source distribution

Copyright (c) 2000, 2017, 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>

登錄成功


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM