当使用AWS上的MySQL命令时出现【ERROR 2002 (HY000): 无法通过套接字连接到本地MySQL服务器】的错误

建立Laravel环境

使用AWS的Cloud9来搭建Laravel的开发环境。

    • MySQLのバージョンアップ(ver5.5 -> ver.5.7)

 

    • PHPのバージョンアップ(ver5.X -> ver.7)

 

    • composerのインストール

 

    Laravel5.5のインストール

进行一些操作,最后创建一个数据库!执行以下命令即可。

sudo mysql --user="root" -e "CREATE DATABASE laravel character set UTF8mb4 collate utf8mb4_bin;"

发生了如下错误。

ERROR 2002 (HY000): Can't connect to local MySQL server through socke

我做了很多调查,但还是无法解决这个问题。

对策的方法

在进行调查的过程中,应进行MariaDB的启动、停止、重新启动和状态确认,并进行相应的处理。

于是,我们首先进行了MariaDB状态的确认。
确认的方法是使用systemctl命令的“status”选项。

sudo systemctl status mariadb

如果启动了,将会显示如下所示。
请注意”Active”部分来确定是否已经启动!
(如果已经启动,则显示为active,如果停止了,则显示为inactive)

● mariadb.service - MariaDB 10.1.44 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2020-05-18 12:38:49 JST; 22h ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 33941 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 9479)
   CGroup: /system.slice/mariadb.service
           mq33941 /usr/sbin/mysqld

May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: Processing databases
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: information_schema
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: mysql
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: performance_schema
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: Phase 6/7: Checking and upgrading tables
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: Processing databases
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: information_schema
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: performance_schema
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: Phase 7/7: Running 'FLUSH PRIVILEGES'
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: OK</pre>

如果是停止状态,将显示如下。

● mariadb.service - MariaDB 10.1.44 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Tue 2020-05-19 10:53:02 JST; 6s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 33941 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 33941 (code=exited, status=0/SUCCESS)
   Status: "MariaDB server is down"

May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: mysql
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: performance_schema
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: Phase 6/7: Checking and upgrading tables
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: Processing databases
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: information_schema
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: performance_schema
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: Phase 7/7: Running 'FLUSH PRIVILEGES'
May 18 12:38:50 development-batch /etc/mysql/debian-start[33977]: OK
May 19 10:53:01 development-batch systemd[1]: Stopping MariaDB 10.1.44 database server...
May 19 10:53:02 development-batch systemd[1]: Stopped MariaDB 10.1.44 database server.

由于我是处于非活动(已停止)状态的,所以我使用以下命令启动了MariaDB!

通过使用systemctl命令中的“start”选项进行启动。使用sudo命令以root权限执行。

sudo systemctl start mariadb

如果再次创建数据库的话

sudo mysql --user="root" -e "CREATE DATABASE laravel character set UTF8mb4 collate utf8mb4_bin;"

取得了成功。

请提供参考资料

非常感谢您。谢谢。

广告
将在 10 秒后关闭
bannerAds