阿里云服务器 ——宝塔面板配置安装的数据库如何进行远程连接

首先在服务器安全组添加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>

登录成功

猜你喜欢

转载自www.cnblogs.com/52lxl-top/p/9862937.html