远程连接 MySQL 与 Redis

MySQL

  • centos 安装 MySQL

    yum install mysql-server
  • 启动 MySQL

    systemctl start mysqld
  • 配置/etc/my.cnf

    bind-address: 0.0.0.0
    skip-networking = 0
  • 以 root 用户连接 MySQL, 修改权限

    GRANT ALL ON *.* TO 'username'@'%' IDENTIFIED BY 'password';
    FLUSH PRIVILEGES; #刷新权限
  • 修改用户密码

    ALTER USER 'username'@'host' IDENTIFIED BY 'new_password';
  • 打开对应的端口

    # 云服务器后台配置
    sudo firewall-cmd --zone=public --add-port=<port>/tcp --permanent
    sudo firewall-cmd --reload
  • 重新启动 MySQL

    systemctl restart mysqld
  • 开机自启动

    systemctl enable mysqld
  • 远程连接 MySQL

    mysql -u<username> -p -h <host> -P <port>

Redis

  • 安装 Redis

    yum install redis
  • 配置 /etc/redis.conf

    bing 0.0.0.0
    requirepass <password>
    port <port>
  • 打开对应的端口

    # 云服务器后台配置
    sudo firewall-cmd --zone=public --add-port=<port>/tcp --permanent
    sudo firewall-cmd --reload
  • 启动 Redis

    systemctl start redis
  • 开机自启动

    systemctl enable redis
  • 远程连接

    redis-cli -h <host> -p <port>