mysqlError: Can't connect to MySQL server on 'localhost' (10061)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zcw4237256/article/details/79978313

博主不才 用的免安装版本的mysql  突然报错很慌

后来也没怎么查看乱七八糟的解决方案,直接从书上找的这个方案,当然可能有别的 欢迎评论:


解决方法(针对WIN系统):
1, 首先到系统服务里面找到MYSQL服务并启动MYSQL服务.
2, 到MYSQL安装目录找到MY.INI文件,打开MY.INI查找max_connections 修改连接数为1000 重启IIS与MYSQL服务.

window 下
命令行下输入:
>cd E:\mysql\bin
>mysqladmin -u root password 你的密码
>mysql -u root -p
Enter password: 你的密码
便可以

、、、、、、、、、、、、、、、、、
找到了根本原因,在此凉一下:

导致此问题的根源在:因为给mysql的root设置了密码,而不是最初安装好时的密码为空,所以使用

mysqladmin version这样子不行了,必须这样子:mysqladmin -uroot -p version,回车后按照提示要求输入

root密码即可成功运行命令。

第一种方法其实就是在不知道root密码的情况下的一种解决办法,那样子启动不用密码即可进mysql

里面并进行root密码的修改,解决忘记了root密码的问题。


输入命令“mysqladmin -u root password 你的密码”作用是修改root用户的密码,这条命令能够不经

提示输入原密码而成功执行,也说明了原密码是空。之后使用修改后的密码自然能够成功登录。
          



阅读更多

频繁出现Can't connect to MySQL server on 'localhost' (10061)

04-20

我的数据库连接代码是rnpublic function open()rn rn $db = new Data_Mysql();rn return $db;rn rn rn function __construct($pconnect = 0)rn rn try rn rn $func = $pconnect==0 ? 'mysql_connect' : 'mysql_pconnect';rn rn $this->link = @$func($this->dbhost, $this->dbuser, $this->dbpw, 1);rn rn $charset1 = $this->dbcharset == '' ? $this->charset : "GB2312";rn rn if(!empty($charset1))rn rn if(function_exists('mysql_set_charset'))rn rn @mysql_set_charset($charset1, $this->link);rn rn else rn rn $collation_query = "SET NAMES '$charset1'";rn $this->Query($collation_query);rn rn rn rn $this->dbname && @mysql_select_db($this->dbname, $this->link);rn rn catch (Exception $e) rn rn if ($this->errno())rn rn throw new Common_MyException("Can't connect to database./数据库服务器连接失败 ");rn rn rn rn rn rn function Query($sql)//执行代码rn rn tryrn rn if(!($result = @mysql_query($sql, $this->link)))rn rn throw new Common_MyException($this->error());rn rn rn catch (Common_MyException $e)rn rn die($e->showStackTrace());rn rn return $result;rn rn rn rn function __destruct()//断开连接rn rn if (!$this->errno())rn rn $this->close();rn rn rn //释放结果集所占用的内存rn function free_result($query) rn return mysql_free_result($query);rn rn rn //返回多条记录rn public function FetchAll($sql)rn rn $returnRows=array();rn tryrn rn if($sql==null) rn rn throw new MyException("查询语句为空."); rn rn if(!($result = $this->Query($sql)))rn rn throw new Common_MyException($this->error());rn rn while ($rows=$this->fetch_array($result)) rn rn $returnRows[]=$rows;rn rn return $returnRows;rn rn rn catch (Common_MyException $e)rn rn die($e->showStackTrace());rn rn rn rn function FetchRow($sql)//返回单条记录rn rn $rows=null;rn rn tryrn rn if($sql==null || $sql=="") rn throw new MyException("查询语句为空.");rn rn rn if(!($result = $this->Query($sql)))rn rn throw new Common_MyException($this->error());rn rn $rows = $this->fetch_array($result);rn rn rn catch (Common_MyException $e)rn rn die($e->showStackTrace());rn rn return $rows;rn rn rn function error() rn return (($this->link) ? mysql_error($this->link) : mysql_error());rn rn rn function errno() rn return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());rn rn rn function select_db($dbname) rn return mysql_select_db($dbname, $this->link);rn rn rn function close() rn return mysql_close($this->link);rn rn rn function num_rows($query) rn $query = mysql_num_rows($query);rn return $query;rn rn rn function result($query, $row = 0) rn $query = @mysql_result($query, $row);rn return $query;rn rn rn function insert_id() rn return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);rn rn rn function fetch_array($query, $result_type = MYSQL_ASSOC) rn return mysql_fetch_array($query, $result_type);rn rnrn可是网站都是频繁报错rnWarning: mysql_set_charset() expects parameter 2 to be resource, boolean given in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 37rnrnWarning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 62rn或者rnWarning: mysql_close(): supplied argument is not a valid MySQL-Link resource in D:\webSite\wwwz2gcomcn\Inc\Data\Mysql.php on line 151rn哪位高手能帮我解决下呀,小弟在这不胜感激rn

MySAL: Can't connect to MySQL server on 'localhost' (10061)

09-03

[b]MySQL版本[/b]:mysql-5.7.4-m14-winx64rn[b]MySQL路径[/b]:D:/mysql/mysql-5.7.4-m14-winx64rn[b]电脑系统[/b]:windows7 旗舰版 sp1 64位系统rnrn[b]my.ini文件配置如下[/b]:rn [color=#333399][client]rn default-character-set=utf8rn rn [mysqld]rn port=3306rn basedir ="D:/mysql/mysql-5.7.4-m14-winx64/"rn datadir ="D:/mysql/mysql-5.7.4-m14-winx64/data/"rn tmpdir ="D:/mysql/mysql-5.7.4-m14-winx64/data/"rn socket ="D:/mysql/mysql-5.7.4-m14-winx64/data/mysql.sock"rn log-error="D:/mysql/mysql-5.7.4-m14-winx64/data/mysql_error.log"rn max_connections=100rn table_open_cache=256rn query_cache_size=1M rn tmp_table_size=32Mrn thread_cache_size=8rn innodb_data_home_dir="D:/mysql/mysql-5.7.4-m14-winx64/data/"rn innodb_flush_log_at_trx_commit =1rn innodb_log_buffer_size=128Mrn innodb_buffer_pool_size=128Mrn innodb_log_file_size=10Mrn innodb_thread_concurrency=16rn innodb-autoextend-increment=1000rn join_buffer_size = 128Mrn sort_buffer_size = 32Mrn read_rnd_buffer_size = 32Mrn max_allowed_packet = 32Mrn explicit_defaults_for_timestamp=truern sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"rn #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES[/color]rnrn在DOS窗口下,输入net start mysql,MySQL服务正常启动。rn通过命令:rn[color=#FF0000]mysql -uroot -p123456[/color] 或者[color=#FF0000]mysql -uroot -p123456 -hlocalhost[/color]rn能够登陆进mysql,并且执行一般的增删改查功能都正常,执行show processlist;结果如下:rn+----+------+----------------+------+---------+------+----------+------------------+rn| Id | User | Host | db | Command | Time | State | Info |rn+----+------+----------------+------+---------+------+----------+------------------+rn| 1 | root | localhost:3707 | NULL | Query | 0 | starting | show processlist |rn+----+------+----------------+------+---------+------+----------+------------------+rn不知道为什么这里会是3707rnrn但是执行命令:[color=#FF0000]mysql -uroot -p123456 -h127.0.0.1[/color]会报错rn错误消息为:ERROR 2004 (HY000): Can't create TCP/IP socket (87)rnhosts文件里面没有设置127.0.0.1 localhost(试过了,事实证明根本没用)rnrnrn有人说是3306端口被占用,我netstat -nao查了一下PID,在任务管理器里面对比,确认是mysqld.exe在用3306,没有其rn他程序占用此端口rn有人说是防火墙的原因,需要把防火墙关了,看了一下我防火墙是关闭的rn有人说是max_connections设置得太小,我设置成1000然后用工具连接mysql依旧报10061错。rn有人说是需要执行授权操作,需要执行命令:[color=#FF0000]GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' rnrnIDENTIFIED BY '123456' WITH GRANT OPTION;[/color](我也试过了,事实证明,没用)rn有人说是因为 my.ini 文件 [mysqld] 项里面没有设置bind-address=127.0.0.1的原因,我也试了,试试证明,如果我rn设置了这个,mysql服务都启动不鸟,又有人说设置成bind-address=0.0.0.0,结果一样的,mysql服务都无法启动,然rnrn后我在又试了一下设置bind-address=192.168.1.101(本机IP),依旧是无法启动mysql。rnrn然后,我试着在DOS下执行:rn[color=#FF0000]mysqladmin -uroot -p123456 version[/color]rn或者rn[color=#FF0000]mysqladmin -uroot -p123456 -hlocalhost version[/color]rn提示错误:rnmysqladmin: [Warning] Using a password on the command line interface can be insecure.rnmysqladmin: connect to server at 'localhost' failedrnerror: 'Unknown MySQL server host 'localhost' (2)'rnCheck that mysqld is running on localhost and that the port is 3306.rnYou can check this by doing 'telnet localhost 3306'rnrn执行:[color=#FF0000]mysqladmin -uroot -p123456 -h127.0.0.1 version[/color]rn提示错误:rnmysqladmin: [Warning] Using a password on the command line interface can be insecure.rnmysqladmin: connect to server at '127.0.0.1' failedrnerror: 'Can't create TCP/IP socket (87)'rnrn期间也试着在hosts里面添加127.0.0.1 localhost然后再执行上面的命令,事实证明,跟这个无关。rnrnrn另外,我试着在DOS里面执行 [color=#FF0000]telnet 127.0.0.1 3306[/color],提示无法打开到主机的连接rn但是,我执行 [color=#FF0000]telnet localhost 3306[/color],能够连进去(这里我也是过在hosts文件里面添加rn127.0.0.1 localhost,事实证明跟这个也没关系)rnrnrn求大神解答,该怎么解决

(急)Can't connect to MySQL server on 'localhost' (10061)

03-07

看了很多解答,多数是因为数据库服务没有启动,我确定我的MySQL服务是启动了的,不知道这个问题和数据库的版本有关系吗?rnrn错误提示:rnWarning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in D:\MYOA\webroot\liuyanban\index.php on line 2rnrnWarning: mysql_select_db() [function.mysql-select-db]: Access denied for user: 'ODBC@localhost' (Using password: NO) in D:\MYOA\webroot\liuyanban\index.php on line 3rnrnWarning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in D:\MYOA\webroot\liuyanban\index.php on line 3rnrnWarning: mysql_query() [function.mysql-query]: Access denied for user: 'ODBC@localhost' (Using password: NO) in D:\MYOA\webroot\liuyanban\index.php on line 4rnrnWarning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\MYOA\webroot\liuyanban\index.php on line 4rnrnWarning: mysql_query() [function.mysql-query]: Access denied for user: 'ODBC@localhost' (Using password: NO) in D:\MYOA\webroot\liuyanban\index.php on line 6rnrnWarning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\MYOA\webroot\liuyanban\index.php on line 6rnrnWarning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in D:\MYOA\webroot\liuyanban\index.php on line 7rnrn初学PHP,请高手帮忙解答!rn

没有更多推荐了,返回首页