so I finished a site locally, and I have been trying to start to transfer it to an online server. And this is probably a really stupid question but I've spent the last hour trying to find the answer and I can't. So this is a line of PHP code being run on the server (with the username and password changed, but the hostname the same):
if(!mysql_connect("www.bluestreakaquatic.com","username","password"))
die(mysql_error());
It produces this error:
Can't connect to MySQL server on 'www.bluestreakaquatic.com' (10061)
Can anyone possibly give me any sort of advice?
Your hosting provider probably doesn't allow external mySQL connections for security reasons.
If mySQL runs on the same server as your site, try replacing the domain name with localhost
.
If that doesn't work, you need to ask your hosting provider for the correct database server address.
I had recently experienced the same problem.
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
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:
You now must flush MySQL's privileges. Run this command:
FLUSH PRIVILEGES;
Run this command to exit MySQL:
exit;
/etc/init.d/mysqld restart
or
/etc/init.d/mysql restart
depending on what linux distro is your server currently running.
It is unlikely that any hosting provider will allow remote connections to mysql server because of security risks. But you may be lucky if your hosting server uses DirectAdmin control panel or cPanel . If so, follow these steps:
Goto MySQL Management
. Select your database and click on it. You will find a section named Access Hosts
. Add a new host: ( %
)
Goto Remote MySQL
under Databases
section and add %
instead of myhost.com
:
Also see the reference: http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html
如果无法从Web服务器连接到远程mysql服务器,但可以从本地主机连接到远程mysql服务器,则该服务器可能没有授予来自该主机的用户名的权限。
GRANT ALL PRIVILEGES ON database.* TO username@serverhostname IDENTIFIED BY 'password'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.