阿里云服务器 ——宝塔面板配置安装的数据库如何进行远程连接
Posted 落雨心星
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了阿里云服务器 ——宝塔面板配置安装的数据库如何进行远程连接相关的知识,希望对你有一定的参考价值。
首先在服务器安全组添加3306放行端口
继而再去面板中添加3306放行端口
在阿里云服务器中登录mysql进行远程配置(权限为root才能配置,否则配置不成功)
1. 先用localhost登录
# mysql -u root -p
Enter password:
2. 执行授权命令
mysql> grant all privileges on *.* to [email protected]‘%‘ identified by ‘password‘; 红色底板的password自行设置
Query OK, 0 rows affected (0.07 sec)
3. 退出再试
mysql> quit
Bye
再试登录:(这里测试用另一台主机(我这里用win10的cmd命令行连接)就能登录,得先连网)
C:UsersASDS>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 [email protected]‘%‘;
Query OK, 0 rows affected (0.00 sec)
登录测试:
C:UsersASDS>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>
登录成功
以上是关于阿里云服务器 ——宝塔面板配置安装的数据库如何进行远程连接的主要内容,如果未能解决你的问题,请参考以下文章
Memcached 如何设置比较好?Linux 服务器中宝塔面板
阿里云服务器Debian11系统安装Linux宝塔面板 搭建WordPress个人博客