Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php连接mysql 错误提示:由于目标计算机积极拒绝,无法连接

php连接mysql 错误提示:由于目标计算机积极拒绝,无法连接

Jun 23, 2016 pm 02:02 PM

用命令提示符操作mysql是没有问题的,包括查询插入更新都没有问题。
php.ini配置如下:;extension=php_mysql.dll
                 ;extension=php_mysqli.dll
                 前面的分号都去掉了呀。
错误提示如下:
Warning: mysql_connect() [function.mysql-connect]: [2002] 由于目标计算机积极拒绝,无法连接。 (trying to connect via tcp://localhost:3306) in F:\Apache\htdocs\ch13\13-1.php on line 6
Warning: mysql_connect() [function.mysql-connect]: 由于目标计算机积极拒绝,无法连接。 in F:\Apache\htdocs\ch13\13-1.php on line 6
数据库连接失败:
由于目标计算机积极拒绝,无法连接。 

php代码如下:

<?php$host='localhost';$user_name='root';$password='admin';$conn = mysql_connect($host,$user_name,$password);if(!$conn){    die('数据库连接失败:<br/>'.mysql_error());}echo '数据库连接成功!';?>
Copy after login


回复讨论(解决方案)

请各位大侠相助,不胜感激

呵呵。。没权限访问吧,你把数据库设置一下

然后用户名密码确定能这样对$user_name='root';
$password='admin';

用户权限的问题,你看看你的 命令提示符操作时是不是没有user数据库啊

估计还是php.ini文件的配置有不对的地方。

这个说明你连接目标机器后,他的系统自动视为是攻击对象了,

你把他的防火墙关了试试

估计是防火墙阻挡了












---------------------------------------------------------------------------------------------
http://www.jiemengwu.com/  解梦屋 http://www.phpzy.com/php/  绿色php资源http://www.shopfw.com 网店服务

用命令提示符操作mysql是没有问题的,包括查询插入更新都没有问题。
php.ini配置如下:;extension=php_mysql.dll
  ;extension=php_mysqli.dll
  前面的分号都去掉了呀。
错误提示如下:
Warning: mysql_connect() [function.mysql-connect]: [2002] 由于目标计算机积极拒绝,无法连……


检查一下用户名和密码是否正确,再检查一下防火墙是否禁止了MYSQL的默认端口

把防火墙关了,在试试,个人经验觉得是防火墙的问题,应该是3306端口被拒绝了

用户权限的问题,你看看你的命令提示符操作时是不是没有user数据库啊
是没有user数据库,该如何设置呢?

我的也没有USER数据库都可以正常连接。

show database显示:几个数据库;
其中没有user数据库,但是在mysql数据库下有一个user表。

防火墙关闭后提示错误依然如旧,我安装的是360安全卫士和360杀毒,这个卸载再试试?

防火墙关闭后提示错误依然如旧,我安装的是360安全卫士和360杀毒,这个卸载再试试?

是PHP5.3吗?如果是的话,估计是你的数据库连接服务器名设置是localhost,改为127.0.0.1即可,

试一下,因为PHP5.3以后不支持直接以localhost进行连接

还有这样的问题啊,从来没碰到过,按它提示的信息应该是防火墙的问题,既然关了都不行,真不知道了,你telnet 127.0.0.1 3306看看能不能登陆上。可能是数据库版本的问题

遇到相同的问题,请高手详细指导,谢谢!

我也遇到过同样的问题,我在程序中加上端口号就行了。
            $conn=mysql_connect("127.0.0.1:3307","root","root") or die (mysql_error());  
    if(!$conn) echo "Failed!";  
    else echo "Successful!";  
    print_r ($conn);  
    mysql_close();  
?> 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Check network connection: lol cannot connect to the server Check network connection: lol cannot connect to the server Feb 19, 2024 pm 12:10 PM

LOL cannot connect to the server, please check the network. In recent years, online games have become a daily entertainment activity for many people. Among them, League of Legends (LOL) is a very popular multiplayer online game, attracting the participation and interest of hundreds of millions of players. However, sometimes when we play LOL, we will encounter the error message "Unable to connect to the server, please check the network", which undoubtedly brings some trouble to players. Next, we will discuss the causes and solutions of this error. First of all, the problem that LOL cannot connect to the server may be

Why can't Bluetooth connect to Windows 10 computer? Why can't Bluetooth connect to Windows 10 computer? Jul 16, 2023 am 08:03 AM

Through Bluetooth devices, we can transfer files without a network connection, or connect Bluetooth headsets to listen to music, etc. However, some netizens recently said that their win10 computer’s Bluetooth cannot connect. What’s going on? The editor below will teach you how to solve the problem that the win10 Bluetooth device cannot be connected. This situation may be caused by a driver problem. The following editor will show you the specific solution: 1. Click the Cortana search box in the lower left corner of win10, enter "Device Manager", click and open "Device Manager". 2. In the device manager, click "Bluetooth". 3. Select "QualcommAtherosBluetooth" in the expanded list. 4. Right-click and select "Update Driver". 5.

Network printer cannot connect Network printer cannot connect Jan 24, 2024 pm 01:53 PM

Solutions for network printers that cannot connect: 1. Network connection problem; 2. Printer setting problem; 3. Driver problem; 4. System file damage; 5. Firewall or anti-virus software settings; 6. Server service not turned on; 7. Sharing The service is not turned on; 8. The computer browser service is not turned on. Detailed introduction: 1. Network connection problem. First, make sure the network connection is normal. You can test the network connection through the ping command. If the computer cannot ping the network printer, there may be a problem with the network connection. You can try restarting the router or switch, etc.

Win10 is recognizing the solution for being unable to connect to the internet Win10 is recognizing the solution for being unable to connect to the internet Jul 11, 2023 pm 06:21 PM

When you use a win10 computer, have you ever encountered a situation where you are unable to connect to the internet? If you don't know how to solve this problem, let's take a look at this article. 1. Use the Win+I key combination to bring up the settings window, click to select Network and Internet. 2. Click Ethernet on the left side of the Network and INTERNET window, and then click Change Adapter Options in the right window. 3. In the Network Connection window, right-click Ethernet (desktop, please treat mobile devices as appropriate), and click Disable in the menu. 4. After it is displayed as disabled, right-click the Ethernet mouse and execute the enable command. Once Ethernet is enabled, the problem should be resolved. Here is an introduction to Win10 network failure prompt identification without

What should I do if Win7 cannot connect to the remote desktop? Tips for solving the problem of Win7 unable to connect to the remote desktop What should I do if Win7 cannot connect to the remote desktop? Tips for solving the problem of Win7 unable to connect to the remote desktop Jun 02, 2024 pm 07:34 PM

Recently, many users using Win7 system have found that they cannot connect to the remote desktop. This is probably caused by registry settings. So how to solve it? Let’s take a look below! 1. First, press the "Win+R" keys to open the run window, and enter the "regedit" command to open the registry editor. 2. Then, in the opened registry interface, click to expand "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\TerminalServerClient". 3. Then, right-click on the blank space and select "

How to solve 0x00000006 Unable to connect to printer How to solve 0x00000006 Unable to connect to printer Nov 07, 2023 pm 12:14 PM

Solutions include checking the connection, checking the driver, checking the network connection, checking the printer status, checking the print queue, restarting the device, etc. Detailed introduction: 1. Check the connection: Make sure the printer is turned on and connected correctly to the computer. If using USB connection, please make sure the USB cable is firmly connected and try changing the USB port; 2. Check the driver: Make sure the printer driver is installed correctly. Try to reinstall or update the printer driver. You can download the latest driver from the printer manufacturer's official website; 3. Check the network connection, etc.

What does it mean when unable to connect to steam network? What does it mean when unable to connect to steam network? Sep 13, 2023 pm 01:24 PM

The inability to connect to the Steam network refers to the situation where the user cannot connect to the Steam server normally when using the Steam platform. The reasons are as follows: 1. Network connection problem, you should check whether the network connection is normal, restart the router, turn off the firewall or add Steam to the exception list of the firewall; 2. Steam server problem, the user can only wait for the Steam server to return to normal; 3. Computer Or problems with the Steam client, update the operating system and drivers, clear the cache of the Steam client, etc.

What to do if there is no local connection in win7 system What to do if there is no local connection in win7 system Jun 29, 2023 pm 01:46 PM

What should I do if there is no local connection in win7 system? Win7 system cannot make local connection. How to solve the problem and share the tutorial. After reinstalling win7 system or just installing a new system on the computer, the user finds that his computer cannot connect to the network. Many users will encounter this situation. The reason is that the computer does not have the corresponding driver, and they need to update it or download the driver. Win7 system cannot perform local connection solution operation tutorial sharing 1. If you find that there is no exclamation mark and question mark in front of the network card driver in the device manager, and the driver is normal, then you should consider the error of the network connection management service program. 2. Press and hold the Win key + R key to open the run window. 3. In order

See all articles