Mysql 报错连接数据库报错

mysql 报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin

mysql> help contents
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> help contents
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

解决办法
1、 修改用户密码
mysql> alter user 'root'@'localhost' identified by 'youpassword';  

或者       

mysql> set password=password("youpassword");
2、刷新权限
mysql> flush privileges;

mysql> help contents
You asked for help about help category: "Contents"
For more information, type 'help <item>', where <item> is one of the following
categories:
   Account Management
   Administration
   Compound Statements
   Data Definition
   Data Manipulation
   Data Types
   Functions
   Functions and Modifiers for Use with GROUP BY
   Geographic Features
   Help Metadata
   Language Structure
   Plugins
   Procedures
   Storage Engines
   Table Maintenance
   Transactions
   User-Defined Functions
   Utility
mysql>

 

远程连接MYSQL数据库,报1130错误的解决方法

重装MySQL,由于不知道重装之前的root密码,使用重装之后的密码连接Mysql数据,总报 ERROR 1130: host 'localhost' not allowed to connect to this MySQLserver,不能连接数据库,猜测用户权限和密码的问题。

1、用root用户登录mysql数据库

(1)停止MySQL服务,执行net stop mysql;

(2)在mysql的安装路径下找到配置文件my.ini,

   找到[mysqld]
   输入:skip-grant-tables,保存

(3)重启mysql服务,net start mysql;

(4)执行mysql -uroot -p,回车,再回车,即可进入mysql数据库;

 

2、在本机登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%'。

mysql>use mysql;

mysql>select host,user,password from user;

mysql>update user set host = '%' where user ='root';

mysql>flush privileges;    #刷新用户权限表

mysql>select host,user,password  from user where user='root';

 

3、插入本地登录的用户

mysql>insert into user values('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y','','','','',0,0,0,0,'','');

此时本地连接的用户localhost密码为空

 

4、修改root密码

(1)用set password 方式修改root密码遇到错误ERROR 1290 (HY000)

mysql> set password for root@'localhost'=PASSWORD('12345');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
cute this statement

注意:以skip-grant-tables方式启动mysql后,不能用直接用set password的方式修改root密码,须注释skip-grant-tables, 然后重启服务,连接数据库修改密码

(2)用update方式修改root密码正常

mysql> update user set password=password("123") where user="root";

mysql>flush privileges; 

 (3)不连接数据库,直接在cmd下修改密码

mysqladmin -uroot -p旧密码 password 新密码,此种方式修改密码也不能在以“skip-grant-tables“方式启动mysql后进行

如:mysqladmin -uroot -p123456 password 1234

5、退出MySQL,在配置文件中注释:skip-grant-tables,重启mysql服务

6、本地重新连接mysql数据库,输入修改后的密码,连接成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
远程主机连接MySQL数据库报错1045通常是由于用户名或密码错误导致的。请确保远程主机使用的用户名和密码正确,并且具有正确的权限来连接MySQL数据库。你可以尝试以下解决方案: 1. 检查用户名和密码:确保你使用的用户名和密码是正确的,并且与远程MySQL数据库中的凭据匹配。 2. 检查用户权限:确保你的用户具有足够的权限来从远程主机连接到MySQL数据库。你可以使用GRANT语句为用户授予适当的权限。 例如,执行以下命令授予用户远程访问权限: ``` GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; ``` 这将授予用户在所有数据库和所有远程主机上的完全权限,你可以根据需要进行调整。 3. 检查防火墙设置:如果你的远程主机上启用了防火墙,确保MySQL端口(默认为3306)在防火墙规则中是开放的,以允许远程连接。 你可以尝试在远程主机上执行以下命令以开放MySQL端口: ``` sudo ufw allow 3306 ``` 4. 检查MySQL配置文件:确保MySQL配置文件中的bind-address参数允许远程连接。默认情况下,它可能被设置为仅允许本地连接。 编辑MySQL配置文件(一般是/etc/mysql/mysql.conf.d/mysqld.cnf或/etc/mysql/my.cnf),找到bind-address行,并将其值设置为0.0.0.0以允许远程连接。 保存并重新启动MySQL服务以使更改生效。 如果问题仍然存在,请提供更多详细信息,例如完整的错误消息和你的操作系统环境,以便我能够提供更具体的帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值