zoukankan      html  css  js  c++  java
  • How to Enable Remote Access to MySQL

    How to Enable Remote Access to MySQL on Ubuntu | Chosen Blog


    How to Enable Remote Access to MySQL

    MySQL remote access is disabled by default, but with a few simple steps, you should be up and running with remote MySQL in just a few minutes. This is especially useful when working with multiple developers in an Agile project environment, so that you all use the same data set, and can focus on just writing the application.

     
    Login to SSH to edit remote MySQL config

    First, we need to edit the mysql config file to accept and bind remote connections to your server. We do this by editing your my.conf file located on most unix systems at /etc/my.conf or /etc/mysql/my.conf. I’m going to hope and assume you know the basics to ssh into your remote server and vi or nano the conf file.

    ssh root@yourserver.com
    vi /etc/my.conf

    Replace mysqld Defaults

    You can either set this up as a new connection or override the default, in this case, I replaced the default connection with my own remote connection settings:

    [mysqld]
    bind-address    = 255.112.324.12
    port            = 3306
    user            = mysql
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    basedir         = /usr
    datadir         = /var/lib/mysql
    tmpdir          = /tmp
    language        = /usr/share/mysql/English
    # skip-networking
    # skip-external-locking

    After your done editing, just save and close the file and restart mysql services:

    # Ubuntu
    service mysql restart
    # Other Unix
    /sbin/init.d/mysql restart
    # Test that your connection is allowed with telnet on your local machine:
    telnet 255.112.324.12 3306

    Granting Remote Access to MySQL Users

    Now we’ve created our remote config for MySQL, we have to grant access to this server to other machines.

    mysql -uroot -pMyPass
    CREATE DATABASE mydb;
    # Grant permission to root from any host:
    GRANT ALL ON mydb.* TO root@'%' IDENTIFIED BY 'MyPASSWORD';

    Open Up MySQL Remote Ports

    Now that our user has been granted access from any host, all thats left is to make sure our OS will allow connections to the default MySQL port

    /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

    And now we should be able to login to our server from our local machine:

    mysql -h255.112.324.12 -uroot -pMyPASSWORD

    Does this work for you? Comments or suggestions?

  • 相关阅读:
    史上最走心的Webpack4.0中级教程——配置之外你应该知道事
    javascript基础修炼(11)——DOM-DIFF的实现
    一统江湖的大前端(7)React.js-从开发者到工程师
    express中间件系统的基本实现
    js中如何在不影响既有事件监听的前提下新增监听器
    Zabbix的应用(6)----常见错误
    Ansible初级应用
    一个好用的小工具 thefuck
    使用python读取word文件里的表格信息
    01010_Eclipse中项目的jar包导入与导出
  • 原文地址:https://www.cnblogs.com/lexus/p/2508259.html
Copyright © 2011-2022 走看看