Remote Mysql access

前端 未结 6 1492
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 15:50

I have problem to connect remote LAN MYSQL. While try following commands it shows the following error.

$ mysql -u root -h 192.168.1.15 -p
mysql>

相关标签:
6条回答
  • 2020-12-18 16:17

    Comment the line below in file /etc/mysql/my.cnf

    # bind-address = 127.0.0.1
    

    And add (any)host permission to login(maybe root) on mysql server.

    Hard way: you need insert in mysql.host table...

    Easy way: use MySQL Administrator->User Administration->Choose user->(Right mouse click)Add host->Select "Any host"

    Finally restart server:

    /etc/init.d/mysql restart
    

    PS: Default install aptitude

    mysql version: MySQL 5.1.57-1~dotdeb.0

    Linux Debian 6 Squeeze

    0 讨论(0)
  • 2020-12-18 16:24

    Just thought I'd throw in another suggestion here...

    Some MySQL GUI tools (Sequel Pro for Mac and EMS SQL Manager for Windows) allow MySQL connections through SSH tunnelling. This means you don't have to grant extra privileges. I have found this to be the fastest way of getting remote access to MySQL databases that I administer.

    0 讨论(0)
  • 2020-12-18 16:29

    If you have full access to your server (root privileges required):

    Step 1: edit my.cnf (usually located in /etc)

    Find the following line: [mysqld] and make sure line skip-networking is commented (or remove line) and add following line:

    bind-address=YOUR-SERVER-IP
    

    For example, if your MySQL server IP is 66.166.170.28 then entire block should be look like as follows:

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

    Where

    • bind-address : IP address to bind to.
    • skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state.

    Step 2: Grant access to all hosts

    Start the MySQL monitor with this command: mysql or /usr/local/mysql/bin/mysql. Your shell prompt should now look like this: mysql>. Run this command:

    GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY "PASSWORD";
    

    Where:

    • USERNAME is the username that you use when connecting using your php script.
    • PASSWORD is the password you use when connecting.

    You now must flush MySQL's privileges. Run this command:

    FLUSH PRIVILEGES;
    

    Run this command to exit MySQL:

    exit;
    

    Step 3: restart mysql deamon

    /etc/init.d/mysqld restart
    

    or

    /etc/init.d/mysql restart
    

    depending on what linux distro is your server currently running.

    0 讨论(0)
  • 2020-12-18 16:30

    As above, getting rid of "skip-networking" in my.cnf need to be done.

    However, on some configurations, that is over-ridden by SKIP="--skip-networking" in a start-up file, such as rc.mysqld. So take that out also.

    Does hosts.allow permit one machine to talk to the other in any case?

    And leave us not forget the actual documentation.

    0 讨论(0)
  • 2020-12-18 16:38

    You should also check that your MySQL server has been configured to accept remote TCP connections.

    In your MySQL configuration file (my.cnf), you need the following at least:

    port         = 3306          # Port MySQL listens on
    bind-address = 192.168.1.15  # IP address of your server
    # skip-networking            # This should be commented out to enable networking
    

    The default in some configurations is for the bind-address to be 127.0.0.1, or to skip networking completely, which means only local or unix socket connections are possible. This is for security reasons.

    You can also configure the bind-address to be 0.0.0.0 which means it will bind on all IP addresses on the server.

    And lastly, check your firewall configuration to allow port 3306.

    0 讨论(0)
  • 2020-12-18 16:39
    GRANT ALL ON test.* TO 'root'@'192.168.1.15' IDENTIFIED BY '';
    
    0 讨论(0)
提交回复
热议问题