mysql root 忘記密碼

來源:互聯網
上載者:User

標籤:shutdown   style   databases   art   init.d   多使用者   使用者數   password   null   

前提:用戶端伺服器端必須在同一台機器上面才能修改 如果mysql庫裡面沒有其他使用者資料,可以直接初始化mysql庫。 但是如果mysql庫建立了很多使用者就不能進行初始化了。只能從新找回密碼要想找回管理員密碼必須停止mysql服務service mysqld stop 然後手動啟動mysql。編輯/etc/init.d/mysqld 找到 有個 $bindir/mysqld_safe --datadir="$datadir" --pid-file="mysqld_pid_file_path" $other_args >/dev/null 2>&1 & 修改為:$bindir/mysqld_safe --skip--grant-tables --skip-networking --datadir="$datadir" --pid-file="mysqld_pid_file_path" $other_args >/dev/null 2>&1 & 再啟動mysql服務。 然後登陸上去後再設定密碼注意這裡再修改密碼時候只能去改mysql.user表裡面的password 欄位了update user set Password=password(‘設定的新密碼‘); where user=‘root‘; 然後在退出mysql,停止mysql服務,重新編輯/etc/init.d/mysqld  把剛才改的欄位再改回去。再重新啟動mysql服務即可  方法2: 使用mysqld_safe  命令加上一些參數,登陸時候不使用授權表 首先停止mysql服務 然後:mysqld_safe --skip-grant-tables --user=mysql &直接新開一個shell輸入mysql即可進入 如果無法進入,提示mysqld_safe Starting mysqld daemon with databases from /mydata/datamysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 請查看/var/log/mysqld.log我查看到日誌顯示這樣:160412  6:21:04 [ERROR] /usr/local/mysql/bin/mysqld: Can‘t create/write to file ‘/var/run/mysqld/mysqld.pid‘ (Errcode: 2)160412  6:21:04 [ERROR] Can‘t start server: can‘t create PID file: No such file or directory160412 06:21:04 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended應該是/var/run/mysqld目錄不存在,系統無法在此目錄找到pid檔案 解決:建立目錄,在目錄下面建立pid檔案 mkdir /var/run/mysqld在目錄下面建立mysqld.pid檔案,並授權該目錄下面的所有檔案為mysql使用者,mysql組 [[email protected] log]# cd /var/run/mysqld[[email protected] mysqld]# touch mysqld.pid[[email protected] run]# chown -R mysql.mysql  mysqld  接著去修改mysqlku裡面user表update mysql.user set password = password(‘your pwd‘); 最後重新整理許可權flush privileges; 最後再啟動mysql服務 之前你使用免密碼登陸之後,mysql服務已經被啟動了,是以無授權表方式啟動的,當你update改完密碼之後,需要重啟mysql服務,你會這樣/etc/init.d/mysqld stop 此時他會提示你PID檔案不存在。因為你之前啟動不是使用/etc/init.d/mysqld  start 啟動的因此就不會產生pid檔案所以不能通過這樣重啟。 正確重啟方式:mysqladmin -u root -p shutdown/etc/init.d/mysqld start

mysql root 忘記密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.