本文章向大家介绍MySQL问题记录--Can't connect to MySQL server on localhost (10061)解决方法,主要包括MySQL问题记录--Can't connect to MySQL server on localhost (10061)解决方法使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
环境:WIN10+MYSQL8.0 或 WIN7+MYSQL5.7
问题描述:在命令行输入 mysql -u root -p 登录mysql,返回”Can't connect to MySQL server on localhost (10061)”错误
解决方法:
(首先切换到mysql的bin目录下,路径不要输错了。本文为:J:\Notes\MySQL5.7\mysql-5.7.24-winx64\bin)
- 将mysql加入到Windows的服务中。切换到mysql安装目录下的bin文件夹,命令行运行"mysqld --install"此时若使用“net start mysql”成功启动msyql,则无须执行下面步骤。
1 执行:mysqld --install
2 结果:Service successfully installed.
- 初始化mysql数据库,输入“mysqld --initialize --user=root --console”。下面红色文字为初始化后的root 密码
1、执行mysqld --initialize --user=root --console
结果:
2023-09-21T04:51:33.182607Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2023-09-21T04:51:35.807607Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-09-21T04:51:37.252607Z 0 [Warning] InnoDB: Creating foreign key constraint
system tables.
2023-09-21T04:51:38.422607Z 0 [Warning] No existing UUID has been found, so we a
ssume that this is the first time that this server has been started. Generating
a new UUID: 8c895039-583a-11ee-944d-88d7f6c3a8f1.
2023-09-21T04:51:38.591607Z 0 [Warning] Gtid table is not ready to be used. Tabl
e 'mysql.gtid_executed' cannot be opened.
2023-09-21T04:51:38.643607Z 1 [Note] A temporary password is generated for root@
localhost: a4w,h,iyh>qN //这是新生成的密码,需要记住
-
此时使用“net start mysql”成功启动msyql
-
输入mysql -u root -p 进入mysql
-
使用生成的密码登录mysql,通过“set password=password('你的密码')”修改密码。此种方法若是无法修改密码,请看6
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
- 修改密码:
mysql> alter user '用户名'@'登录主机' identified by '密码(自定义)';
例如: mysql> alter user 'root'@'localhost' identified by 'afeng666';
- MySQL localhost connect 方法 serverlocalhost connect server mysql mysql localhost connect方法 localhost 39 connect server mysql localhost 39 connect allowed connect server mysql connect remote server mysql mysql错误connect server connection the localhost actions sqlexception connection localhost错误 connections原因 方法mysql