mysql数据库常见报错解决办法
2020-01-03 本文已影响0人
臻霏
以centos7系统为例
报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)解决办法
新装的mysql数据库没有登陆密码,这种错误常出现在这个时候
解决办法是跳过MySQL的密码认证过程,方法如下:
vim /etc/my.cnf
在打开的文档中的[mysqld]字段后边添加
skip-grant-tables
保存退出
重启mysql服务
~]# systemctl restart mysqld.service
~]# service mysqld restart
输入命令
mysql -u root -p
密码直接回车即可
修改密码
mysql> use mysql;
mysql> update user set password=password("******") where user="root";
mysql> flush privileges; # 使修改密码立刻生效
mysql> quit
可能会报错ERROR 1054 (42S22): Unknown column 'password' in 'field list',解决办法如下
报错ERROR 1054 (42S22): Unknown column 'password' in 'field list'解决办法
出现这种问题使原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
mysql> update mysql.user set authentication_string=password('******') where user='root'; #修改密码成功
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; #立即生效
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
正常登陆即可,如果报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.,解决办法如下
报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.的解决办法
--------------------
mysql8用这两句:
set global validate_password.policy=0;
set global validate_password.length=1;
--------------------
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '******';
Query OK, 0 rows affected (0.00 sec)
--------------------
mysql8用这句
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘new pwd’
--------------------
mysql> quit
Bye
[root@xxx ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>