Can't connect to MySQL server on (ip or domain name)

前端 未结 6 2139
旧巷少年郎
旧巷少年郎 2021-02-13 16:48

I\'m trying to configure a web server (Debian 7). I followed this tutorial. I\'m renting my server thanks to gandi.net service. And i have now apache2, mysql, php5 up and runnin

相关标签:
6条回答
  • 2021-02-13 17:15

    sudo vim /etc/ssh/sshd_config

    set localhost in the file httpd.conf as follows

    ServerName localhost

    or else the port won't accept your server request, and will show cant connect to server ip_address

    0 讨论(0)
  • 2021-02-13 17:17

    If you do a normal install of MySQL on Debian, it will be configured to block external connections to the database.

    This means that you still need to tell MySQL that external access is OK. To do this, you need to update the bind address for MySQL. This is configured in my.cnf, which, on Debian based systems, is located in /etc/mysql/my.cnf.

    In there, find the section that says

    [mysqld]
    

    In there, you must make sure that

    • the line skip-networking is either commented (comments start with a '#') or not there, and
    • Bind-address is set to either 0.0.0.0 (which it is if there is no line bind-address) or to your server's IP-address.

    After doing this, you should restart your MySQL service. Then you need to create a user that is allowed remote access. This can be done with a SQL query:

    GRANT ALL ON yourdatabase.* TO youruser@'*' IDENTIFIED BY 'yourpassword';
    

    You can switch out the asterisk for the IP-address you will connect from, if it's the same every time.

    Finally , you need to open port 3306 (the port MySQL uses) on your firewall. This usually isn't neccesary as it is already open on most systems, but it can be done using the following iptables command.

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

    Source: 1

    0 讨论(0)
  • 2021-02-13 17:26

    I fix the issue by simply running this line on terminal

    ALTER USER 'your_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
    

    your_user = root for me
    your_password = something choose what ever you want

    0 讨论(0)
  • 2021-02-13 17:29
    1. locate my.cnf
    2. vi < copy the path >
      for e.g. ==> vi /usr/local/etc/my.cnf
    3. Now you see and compare below if you find difference then update
    # Default Homebrew MySQL server config  
    [mysqld]
    # Only allow connections from localhost  
    bind-address = 0.0.0.0
    

    Now press button => esc and :wq (vi commands)

    Restart the MySQL =>

    sudo /usr/local/mysql/support-files/mysql.server stop
    sudo /usr/local/mysql/support-files/mysql.server start
    

    Now good to go...

    0 讨论(0)
  • 2021-02-13 17:33

    This is the solution that worked for me: In Debian 7 look in the my.cnf under /etc/mysql/my.cnf and find the following lines:

    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address        = 127.0.0.1
    

    Now change the 127.0.0.1 to the IP address of the mysql server, you want to connect or 0.0.0.0 for no restriction.

    0 讨论(0)
  • 2021-02-13 17:34

    I was trying to find .cnf file hence I did the following:

    sudo find / -name "*.cnf"
    
    /etc/mysql/mysql.conf.d/mysqld.cnf
    /etc/mysql/my.cnf
    /etc/mysql/mysql.cnf
    /etc/mysql/conf.d/mysqldump.cnf
    /etc/mysql/conf.d/mysql.cnf
    

    I edited /etc/mysql/mysql.conf.d/mysqld.cnf based on

    strace mysql ";" 2>&1  | grep cnf
    
    stat("/etc/my.cnf", 0x7ffda9472660)     = -1 ENOENT (No such file or directory)
    stat("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=683, ...}) = 0
    open("/etc/mysql/my.cnf", O_RDONLY)     = 3
    stat("/etc/mysql/conf.d/mysql.cnf", {st_mode=S_IFREG|0644, st_size=8, ...}) = 0
    open("/etc/mysql/conf.d/mysql.cnf", O_RDONLY) = 4
    stat("/etc/mysql/conf.d/mysqldump.cnf", {st_mode=S_IFREG|0644, st_size=55, ...}) = 0
    open("/etc/mysql/conf.d/mysqldump.cnf", O_RDONLY) = 4
    stat("/etc/mysql/mysql.conf.d/mysqld.cnf", {st_mode=S_IFREG|0644, st_size=3034, ...}) = 0
    open("/etc/mysql/mysql.conf.d/mysqld.cnf", O_RDONLY) = 4
    stat("/etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf", {st_mode=S_IFREG|0644, st_size=21, ...}) = 0
    open("/etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf", O_RDONLY) = 4
    stat("/root/.my.cnf", 0x7ffda9472660)   = -1 ENOENT (No such file or directory)
    stat("/root/.mylogin.cnf", 0x7ffda9472660) = -1 ENOENT (No such file or directory)
    

    And changed bind-address to my local IP address.

    0 讨论(0)
提交回复
热议问题