Mysql问题汇总(docker)

138 阅读1分钟

1.启动失败:

$ mysql -h localhost -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

reason: 请记住 localhost 和 127.0.0.1 在这种情况下不是一回事:

  • 如果 host 设置为localhost,则使用套接字或管道。
  • 如果 host 设置为127.0.0.1,则客户端被迫使用TCP/IP。

如果数据库正在侦听监听连接TCP则需要mysql -h 127.0.0.1如果需要通过套接字连接到数据库,请使用mysql -h localhost

$ mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.29 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>