1. 程式人生 > >MySQL執行錯誤解決:Can't connect to MySQL server on localhost (10061)解決方法

MySQL執行錯誤解決:Can't connect to MySQL server on localhost (10061)解決方法

問題描述: 在命令列輸入 mysql -u root -p 登入mysql,返回”Can’t connect to MySQL server on localhost (10061)”錯誤。 在這裡插入圖片描述 解決方法: 1、將mysql加入到Windows的服務中。切換到mysql安裝目錄下的bin資料夾,命令列執行"mysqld --install",如果報錯,則使用管理員賬號執行此命令。

C:\Program Files\MySQL\MySQL Server 5.7\bin> mysqld --install
Service successfully installed.

此時若使用“net start mysql”成功啟動msyql,則無須執行下面步驟

2、初始化mysql資料庫,輸入“mysqld --initialize --user=root --console”。“A temporary password is generated for [email protected]: u).ig.Gd.7hW”冒號後是重置後的密碼。

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysqld --initialize --user=root --console
2016-10-29T01:35:44.309833Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2016-10-29T01:35:46.659968Z 0 [Warning] InnoDB: New log files created, LSN=45790

2016-10-29T01:35:47.154996Z 0 [Warning] InnoDB: Creating foreign key constraintsystem tables.
2016-10-29T01:35:47.362008Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating
a new UUID: 043563f4-9d78-11e6-a8c8-606dc79c383c.
2016-10-29T01:35:47.388009Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-10-29T01:35:47.401010Z 1 [Note] A temporary password is generated for 
[email protected]
: u).ig.Gd.7hW

3、此時使用“net start mysql”成功啟動msyql 4、使用生成的密碼登入mysql,執行下述命令修改密碼:

mysql>  use mysql;
Database changed
mysql> update user set password=password('root') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql>  flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

登入吧,玩的開心!

C:\Users\tarena>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>