search

Home  >  Q&A  >  body text

php - How to modify the mysql port and open it to the outside world. .

How to modify the mysql port and open it to the outside world. . Is there any particularly simple method that currently uses port 3306 to prevent external network access?

某草草某草草2811 days ago758

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:06:41

    The following is for the redhat/centos system, please make adjustments accordingly for other systems:
    1. If you are sure that the process can be opened correctly, go to step 2. If not, please make sure that the program can be opened correctly
    2. Modify the listening port:

        修改MySQL配置文件/etc/my.cnf,在[mysqld]找到如下配置:
        bind-address = 127.0.0.1
        注释掉该行或改成0.0.0.0,然后重启mysql。

    3. Authorize remote users:

        # %表示所有客户端IP
        mysql> grant all on *.* to user_name@"%" identified by "user_password"; 
    
        # 刷新权限:
        FLUSH PRIVILEGES;

    4. Firewall open port:

        打开防火墙配置:
        vim  /etc/sysconfig/iptables
        
        增加一行:
        -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
        
        重启防火墙:
        service  iptables restart

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:06:41

    I took a look just now. My.ini is the configuration file of mysql. If you change the port, it should be fine.

    
    [client]
    port=3306
    [mysql]
    default-character-set=gbk
    
    [mysqld]
    port=3306
    basedir="C:/Program Files/phpStudy/MySQL/"
    datadir="C:/Program Files/phpStudy/MySQL/data/"
    character-set-server=gbk
    default-storage-engine=MyISAM
    sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    max_connections=512
    
    query_cache_size=0
    table_cache=256
    tmp_table_size=18M
    
    thread_cache_size=8
    myisam_max_sort_file_size=64G
    myisam_sort_buffer_size=35M
    key_buffer_size=25M
    read_buffer_size=64K
    read_rnd_buffer_size=256K
    sort_buffer_size=256K
    
    innodb_additional_mem_pool_size=2M
    
    innodb_flush_log_at_trx_commit=1
    innodb_log_buffer_size=1M
    
    innodb_buffer_pool_size=47M
    innodb_log_file_size=24M
    innodb_thread_concurrency=8
    

    reply
    0
  • Cancelreply