mysql資料庫已啟動,但是登入資料庫報錯

來源:互聯網
上載者:User

標籤:mysql資料庫已啟動但是登入資料庫報

mysql資料庫預設設定的是開機自啟動,重啟db01伺服器後,想進入資料庫查看資料資訊:但是無法進入資料庫,報錯如下:

[[email protected] ~]# mysql -uroot -pEnter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql/mysql.sock' (2)

查看mysql資料庫連接埠狀態,嘗試重啟,關閉資料庫,但是報錯如下:

[[email protected] ~]# lsof -i:3306COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEmysqld  1369 mysql   11r  IPv4   9721      0t0  TCP *:mysql (LISTEN)  sqld  1369 mysql   34u  IPv4  10594      0t0  TCP localhost:mysql->localhost:33160 (ESTABLISHED)mysqld  1369 mysql   50u  IPv4  10916      0t0  TCP localhost:mysql->localhost:33176 (ESTABLISHED)mysqld  1369 mysql   51u  IPv4  10919      0t0  TCP localhost:mysql->localhost:33178 (ESTABLISHED)java    1444 nginx  128u  IPv4  10556      0t0  TCP localhost:33160->localhost:mysql (ESTABLISHED)java    1444 nginx  135u  IPv4  10914      0t0  TCP localhost:33176->localhost:mysql (ESTABLISHED)java    1444 nginx  136u  IPv4  10917      0t0  TCP localhost:33178->localhost:mysql (ESTABLISHED)[[email protected] ~]# service mysqld statusMySQL is running but PID file could not be found           [FAILED][[email protected] ~]# /etc/init.d/mysqld restartMySQL server PID file could not be found!                  [FAILED]Starting MySQL.......The server quit without updating PID file (/data/mysql/mysql.pid).                     [FAILED][[email protected] mysql]# /etc/init.d/mysqld stopMySQL server PID file could not be found!                  [FAILED][[email protected] mysql]# /etc/init.d/mysqld startStarting MySQL.....The server quit without updating PID file (/data/mysql/mysql.pid).                     [FAILED]

解決方案

完善mysql設定檔:

如果確認mysql服務正常運行,還提示文章標題的此錯誤,那就是“/etc/my.cnf”設定檔的問題了。解決辦法是修改“/etc/my.cnf”設定檔,在設定檔中添加“[client]”選項和“[mysql]”選項,並使用這兩個選項下的“socket”參數值,與“[mysqld]”選項下的“socket”參數值,指向的socket檔案路徑完全一致。如下:

 

[mysqld]datadir=/data/mysql/mysqlsocket=/data/mysql/mysql.sock...省略n行(愛E族)...[client]default-character-set=utf8socket=/data/mysql/mysql.sock[mysql]default-character-set=utf8socket=/data/mysql/mysql.sock

配置完/etc/my.cnf後,重啟伺服器後,然後就可以正常進入資料庫了



參考文檔:

https://www.cnblogs.com/wzg123/p/6723338.html

mysql資料庫已啟動,但是登入資料庫報錯

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.