阿里云配置Mysql数据库远程链接

本文详细介绍了如何在阿里云上配置Mysql数据库以支持远程访问,包括登录Mysql数据库、更新用户访问权限、刷新权限表及检查端口开放状态等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


在阿里云上搭建好了Mysql,希望可以用远程访问。这个时候就需要设置一下阿里云服务器的一些配置。

1.先登录阿里云的Mysql数据库

先远程到阿里云的服务器
执行脚本 mysql -u root -h localhost -p    【其中root表示数据库登录名】
再输入数据库的密码
root@iZm5ehcixm5361wjbi0od4Z:~# mysql -u root -h localhost -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu)
...(过多省略)
affiliates. Other names may be trademarks of their respective
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2.打开mysql数据库

在 mysql命令模式下执行脚本  use mysql
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

3.设置可以访问的用户

  1. 更新user=‘root’ and host=‘localhost’ 的host数据
    1).host设置为 % 或者 设置为 指定的IP 表示任何IP进行访问该数据库 (笔者就是用这种)
    eg: update user set host=’%’ where user=‘root’ and host=‘localhost’;
    2).host设置为指定的ip 表示只有该IP才能访问该数据库
    eg: update user set host=‘180.168.134.210’ where user=‘root’ and host=‘localhost’;
  2. 创建一个新用户
    执行命令 => grant 权限列表 on 数据库 to ‘用户名’@‘访问主机’ identified by ‘密码’;
    eg: grant all on . to ‘newusername’@’%’ identified by ‘Navicat_123’;
mysql> update user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

4.刷新权限表,让上面的改动生效

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

5.确认阿里云的端口是否开放

mysql的默认端口是3306,如果阿里云上设置未设置对外,可以[ 点击这里去看看阿里云的安全规则配置文档 ]

6.上面的都搞定了,如图,远程链接搞定啦!

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值