《MYSQL数据库浅谈mysql密码遗忘和登陆报错的问题》要点:
本文介绍了MYSQL数据库浅谈mysql密码遗忘和登陆报错的问题,希望对您有用。如果有疑问,可以联系我们。
MYSQL应用mysql登录暗码忘记,其实解决办法很简单,只需要在mysql的主配置文件my.cnf里添加一行“跳过授权表”的参数选择即可!
MYSQL应用在my.cnf中添加下面一行:
MYSQL应用[root@test-huanqiu ~]# vim /etc/my.cnf //在[mysqld]区域里添加
........
skip-grant-tables //跳过授权表
MYSQL应用然后重启mysql服务,即可无暗码登录
MYSQL应用[root@test-huanqiu ~]# /etc/init.d/mysqld restart
MYSQL应用登录后重置暗码
MYSQL应用[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应用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应用mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MYSQL应用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应用mysql>
MYSQL应用再次将my.cnf里添加的那一行注释,然后重启mysql
MYSQL应用[root@test-huanqiu ~]# vim /etc/my.cnf
........
#skip-grant-tables
MYSQL应用[root@test-huanqiu ~]# /etc/init.d/mysqld restart
MYSQL应用[root@test-huanqiu ~]# mysql -p123456
mysql>
MYSQL应用-----------------------------------------------------------------------------------------------------------------------
MYSQL应用发现的一个坑:
MYSQL应用mysql之前进行了全量备份,在恢复后,发现用之前的暗码登陆不进去了!
使用上面的方法,无暗码登陆后再重置暗码,但是重置暗码后发现仍然登陆不进去.
MYSQL应用最后发现是因为mysql.user表内容被清空了!
mysql> select host,user,password from user;
Empty set (0.00 sec)
MYSQL应用解决:
MYSQL应用插入数据,再重置暗码
MYSQL应用
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应用然后使用重置后的暗码就能正常登陆了!
MYSQL应用------------------------------------------------------------------------------------------------------------------
MYSQL应用mysql登录报错1:
MYSQL应用[root@test-huanqiu ~]# mysql -p123456
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
MYSQL应用[root@test-huanqiu ~]# ps -ef|grep mysql
root 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.pid
mysql 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=3306
root 30726 11268 0 12:58 pts/2 00:00:00 grep mysql
MYSQL应用可知,当前mysql.sock文件路径是/usr/local/mysql/var/mysql.sock,
MYSQL应用解决办法:做软链接
MYSQL应用[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
MYSQL应用这样就没问题了
MYSQL应用[root@test-huanqiu ~]# mysql -p123456
mysql>
MYSQL应用----------------------------------------------------------------------------------------------------
MYSQL应用启动mysql的时候报错:
MYSQL应用Starting MySQL.... ERROR! The server quit without updating PID file (/data/mysql/data/mysql.pid).
MYSQL应用尝试的解决办法:
MYSQL应用(1)权限问题
MYSQL应用可能是mysql.pid文件没有写的权限,将mysql的安装目录和数据目录的权限都设置成mysql启动用户权限.比如都修改为mysql:mysql权限
MYSQL应用(2)可能进程里已经存在mysql进程
MYSQL应用ps -ef|grep mysql 查出要是有mysql进程存在,就kill掉,再尝试重启mysql
MYSQL应用(3)可能是多次在机器上安装mysql,有残余数据影响了服务的启动.
MYSQL应用去mysql的数据目录看看,如果存在mysql-bin.index,就立刻删掉它,它就是罪魁祸首了!
MYSQL应用(4)mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录.
MYSQL应用在[mysqld]下添加设置,如datadir = /data/mysql/data
MYSQL应用(5)skip-federated字段问题
MYSQL应用检查一下my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉.
MYSQL应用(6)错误日志目录不存在
MYSQL应用去my.cnf文件下是否有log日志配置路径,如果有,查看下日志目录是否存在,日志目录权限要确保是mysql启动用户权限.
MYSQL应用(7)selinux惹的祸,如果是centos系统,默认会开启selinux
MYSQL应用闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试.
(8)重新初始化mysql数据试试
MYSQL应用切换到mysql的安装目录下
MYSQL应用./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
MYSQL应用--------------------------------
MYSQL应用使用mysql服务端授权的信息登录mysql,报错如下:
MYSQL应用ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.14' (111)
MYSQL应用可能的原因有:
MYSQL应用1)可能网络连接问题,远程ping 192.168.1.14 ,能ping通,排除此情况;
MYSQL应用2)mysql服务端192.168.1.14的iptables里做了3306端口连接的白名单限制;
MYSQL应用3)mysql服务端192.168.1.14的my.cnf文件里配置了bind_address地址绑定,不允许本机连接;
MYSQL应用4)mysql服务端192.168.1.14的my.cnf文件里配置了skip_networking,这使用MySQL只能通过本机Socket连接(socket连接也是本地连接的默认方式),放弃对TCP/IP的监听;
MYSQL应用5)排查DNS解析问题,检查mysql服务端192.168.1.14的my.cnf文件里是否设置了skip_name_resolve.这个参数加上后,不支持主机名的连接方式.
MYSQL应用6)排查--port问题,有可能mysql服务端192.168.1.14的MySQL port不是默认3306,比如是3307端口,这样,远程连接的时候要加上--port=3307
MYSQL应用7)排查用户和暗码问题, 其实用户和暗码的错误,不会出现111的,所以排除用户暗码问题
ERROR 1045 (28000): Access denied for user 'root'@'XXXX' (using password: YES)
MYSQL应用以上这篇浅谈mysql暗码遗忘和登陆报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持维易PHP.
欢迎参与《MYSQL数据库浅谈mysql密码遗忘和登陆报错的问题》讨论,分享您的想法,维易PHP学院为您提供专业教程。
转载请注明本页网址:
http://www.vephp.com/jiaocheng/9530.html