重装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 [email protected]‘localhost‘=PASSWORD(‘12345‘);
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
cute this statement
(2)用update方式修改root密码正常
mysql> update user set password=password("123") where user="root";
mysql>flush privileges;
5、退出MySQL,在配置文件中注销:skip-grant-tables,重启mysql服务
6、本地重新连接mysql数据库,输入修改后的密码,连接成功