下面小編就為大家帶來一篇淺談mysql密碼遺忘和登陸報錯的問題。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧
mysql登入密碼忘記,其實解決方法很簡單,只需要在mysql的主設定檔my.cnf裡加入一行「跳過授權表」的參數選擇即可!
在my.cnf中加入下面一行:
[root@test-huanqiu ~]# vim /etc/my.cnf //在[mysqld]区域里添加 ........ skip-grant-tables //跳过授权表
然後重新啟動mysql服務,即可無密碼登入
[root@test-huanqiu ~]# /etc/init.d/mysqld restart
登入後重設密碼
[root@test-huanqiu ~]# mysql mysql> select host,user,password from mysql.user; +--------------------+------+-------------------------------------------+ | host | user | password | +--------------------+------+-------------------------------------------+ | localhost | root | *481ACA1BD6D1E86221244904E9C0FABA33B40B84 | | host-192-168-1-117 | root | | | 127.0.0.1 | root | | | ::1 | root | | | localhost | | | | host-192-168-1-117 | | | +--------------------+------+-------------------------------------------+ 6 rows in set (0.00 sec) mysql> update mysql.user set password=password("123456") where host="localhost" and user="root"; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> select host,user,password from mysql.user; +--------------------+------+-------------------------------------------+ | host | user | password | +--------------------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | host-192-168-1-117 | root | | | 127.0.0.1 | root | | | ::1 | root | | | localhost | | | | host-192-168-1-117 | | | +--------------------+------+-------------------------------------------+ 6 rows in set (0.00 sec) mysql>
再次將my.cnf裡面新增的那一行註解,然後重啟mysql
##
[root@test-huanqiu ~]# vim /etc/my.cnf........#skip-grant-tables [root@test-huanqiu ~]# /etc/init.d/mysqld restart [root@test-huanqiu ~]# mysql -p123456mysql>
# -------------------------------------------------- -------------------------------------------------- -------------------
發現的一個坑:
mysql> select host,user,password from user; Empty set (0.00 sec)
解決:
#插入資料,再重設密碼
mysql> insert into user(host,user,password) values("localhost","root","123456"); Query OK, 1 row affected, 3 warnings (0.01 sec) mysql> select host,user,password from user; +-----------+------+----------+ | host | user | password | +-----------+------+----------+ | localhost | root | 123456 | +-----------+------+----------+ 1 row in set (0.00 sec) mysql> update mysql.user set password=password("123456") where host="localhost" and user="root"; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host,user,password from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +-----------+------+-------------------------------------------+ 1 row in set (0.00 sec) mysql> insert into user(host,user,password) values("127.0.0.1","root","123456"); Query OK, 1 row affected, 3 warnings (0.00 sec) mysql> select host,user,password from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | 127.0.0.1 | root | 123456 | +-----------+------+-------------------------------------------+ 2 rows in set (0.00 sec) mysql> update mysql.user set password=password("123456") where user="root"; Query OK, 1 row affected (0.00 sec) Rows matched: 2 Changed: 1 Warnings: 0 mysql> select host,user,password from user; +-----------+------+-------------------------------------------+ | host | user | password | +-----------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +-----------+------+-------------------------------------------+然後使用重置後的密碼就能正常登陸了!
----------------------------------------- -------------------------------------------------- -----------------------
mysql登入報錯1:
[root@test-huanqiu ~]# mysql -p123456ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) [root@test-huanqiu ~]# ps -ef|grep mysqlroot 28279 1 0 12:55 ? 00:00:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/data/mysql.pidmysql 29059 28279 0 12:55 ? 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql/data/mysql-error.log --pid-file=/data/mysql/data/mysql.pid --socket=/usr/local/mysql/var/mysql.sock --port=3306root 30726 11268 0 12:58 pts/2 00:00:00 grep mysql可知,目前mysql.sock檔案路徑是/usr/local/mysql/var/mysql.sock,
解決方法:做軟連結##
[root@test-huanqiu ~]# ll /usr/local/mysql/var/mysql.sock rwxrwxrwx. 1 mysql mysql 0 Nov 29 12:55 /usr/local/mysql/var/mysql.sock [root@test-huanqiu ~]# rm -f /var/lib/mysql/mysql.sock [root@test-huanqiu ~]# ln -s /usr/local/mysql/var/mysql.sock /var/lib/mysql/mysql.sock
[root@test-huanqiu ~]# mysql -p123456 mysql>
啟動mysql的時候報錯:
Starting MySQL.... ERROR! The server quit without updating PID file (/data/mysql/data/mysql.pid).
嘗試的解決方法:
(1)權限問題
可能是mysql.pid檔案沒有寫的權限,將mysql的
目錄和資料目錄的權限都設定成mysql啟動使用者權限。例如都修改為mysql:mysql權限
(2)可能進程裡已經存在mysql進程
ps -ef|grep mysql 查出要是有mysql進程存在,就kill掉,再嘗試重啟mysql
(3)可能是多次在機器上安裝mysql,有殘餘資料影響了服務的啟動。
(4)mysql在啟動時沒有指定設定檔時會使用/etc/my.cnf設定文件,請開啟這個檔案查看在[mysqld]節下有沒有指定資料目錄。
在[mysqld]下加入設置,如datadir = /data/mysql/data
(5)skip-federated字段問題
去my.cnf檔案下是否有log日誌配置路徑,如果有,查看下日誌目錄是否存在,日誌目錄權限要確保是mysql啟動使用者權限。
(7)selinux惹的禍,如果是centos系統,預設會開啟selinux
閉它,開啟/etc/selinux/config,把SELINUX=enforcing改為SELINUX=disabled後記憶體退出重啟機器試試。 (8)重新初始化mysql資料試試看
切換到mysql的安裝目錄下
./scripts/mysql_install_db -- basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql服務端授權的資訊登入mysql,報錯如下:
4)mysql服務端192.168.1.14的my.cnf檔案裡配置了skip_networking,這使用MySQL只能透過本機Socket連線(socket連線也是
本地連線的預設方式),放棄對TCP/IP的監聽;
5)檢查DNS解析問題,檢查mysql服務端192.168.1.14的my.cnf檔案裡是否設定了skip_name_resolve。這個參數加上後,不支
持主機名稱的連線方式。
6)排查--port問題,有可能mysql服務端192.168.1.14的MySQL port不是預設3306,例如是3307端口,這樣,遠端連線的時候要加上--port= 3307
7)排查使用者和密碼問題,其實使用者和密碼的錯誤,不會出現111的,所以排除使用者密碼問題
ERROR 1045 (28000) : Access denied for user 'root'@'XXXX' (using password: YES)
以上是mysql密碼遺忘與登陸錯誤問題的解決方法分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!