host = localhost user = root password = "" port = 3306 socket = "C:/xampp/mysql/mysql.sock"
在MySQL的使用过程中,我们可能会碰到“Access denied for user 'root'@'localhost' (using password:YES)”的问题,那么接下来我们就来解决它。
经过我的百度查询最后得出结论:出现这种错误有两种可能,一是MySQL的root用户的密码错误,二是权限不够的问题。通常解决办法是修改密码。。。
由于我使用的是Windows系统,所以方法也是Windows系统的修改方法:
1、开始 → 搜索栏里面输入cmd → 右键cmd.exe选择以管理员的身份运行(亦可以在C:\Windows\System32目录下找到这个cmd.exe,右键,以管理员身份运行)
2、输入net stop mysql停止MySQL服务
3、输入命令行来到mysql的bin目录下,输入下列粗体命令
D:\MySQL\bin>mysqld --defaults-file="D:\MySQL\my.ini" --console --skip-grant-tables
等一下,显示出以下结果说明MySQL启动:
170215 22:26:09 [Warning] The syntax '--log' is deprecated and will be removed inMySQL 7.0. Please use '--general_log'/'--general_log_file' instead. 170215 22:26:09 [Warning] The syntax '--log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '--slow_query_log'/'-- slow_query_log_file' instead. 170215 22:26:09 [Warning] The syntax '--log' is deprecated and will be removed in MySQL 7.0. Please use '--general_log'/'--general_log_file' instead. 170215 22:26:09 [Warning] The syntax '--log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file' instead. 170215 22:26:09 [ERROR] The update log is no longer supported by MySQL in version 5.0 and above. It is replaced by the binary log. Now starting MySQL with --log-bin='' instead. 170215 22:26:09 InnoDB: Started; log sequence number 0 324221 170215 22:26:09 [Note] mysqld: ready for connections.Version: '5.1.33-community-log' socket: '' port: 3306 MySQL Community Server (GPL)
4、再以管理员的身份打开一个cmd.exe,输入命令行来到mysql的bin目录下,输入:mysql -uroot mysql
5、进入mysql之后,输入命令行修改密码:
mysql>update user set authentication_string=password('123456') where user='root';
6、刷新权限:mysql>flush privileges;
7、退出mysql:mysql> quit;
8、关闭MySQL:D:\MySQL\bin>mysqladmin shutdown(出现错误,则:mysqladmin -uroot -p shutdown 然后输入新密码)
9、至此修改密码完成,可以输入命令行:net start mysql 启动MySQL服务,mysql -uroot -p ,输入密码就可以进入mysql了。
1、出现这个问题的原因之一是权限的问题,也就是说你的电脑可能没有权限访问mysql数据库。
讲道理这种情况其实基本上不该遇到,因为我们在安装mysql之后,root其实是有最高权限的,而且很少会有人去修改root的权限。
这个问题的解决方法就是授权。授权命令大概是这样的:
grant all privileges on *.* to 'root'@'我电脑的ip地址' identified by '密码';
如果你不是用root登陆的,那么就把root改成你的登陆名。 有的同学可能不知道这个命令往哪里写,
开始——运行——输入“cmd”——点击确定
这样就打开了我们的命令提示符界面:
然后找到我们的mysql的安装目录,将目录复制到命令提示符中。如图:
(cd 是什么意思我想不用特别解释了吧)
然后进入目录下的bin文件:
然后输入 mysql -u root -p 如图:
在Enter password: 后面输入你的密码。点击回车。
如果密码正确,会出现Welcome 的字符。
如图:
这样就成功进入了mysql数据库。
当然如果你已经设置了环境变量,那么不用进入mysql目录,直接输入mysql -uroot就可以了。
当然,你也可以直接打开mysql下的bin窗口,然后按住shift+鼠标右键,选择“在此处打开命令窗口”,就可以直接在bin目录下打开命令提示符窗口了。
接下来就简单了,直接将上面的代码修改一下就可以用了。比如我的电脑的ip地址是:192.168.0.103,我的root密码是:123456,那么我就可以将授权的语句改成:
grant all privileges on *.* to 'root'@'192.168.0.103' identified by '123456'; 如果你是本地登录的,那么: grant all privileges on *.* to 'root'@'localhost' identified by '123456'; 当然你也可以直接改成这样: grant all privileges on *.* to 'root'@'%' identified by '123456'; 就可以给所有ip都设定root登陆了。 如果授权成功,会有Query OK的提示。 然后: flush privileges; 这个是刷新授权的意思,如果没有这句话,授权可能无法立刻生效。 exit; 这个是退出的意思。 授权完成以后,你可以再尝试一下登陆,看看能不能登上。反正我登陆不上。
前言 在windows上开启远程访问权限的时候查找了许多资料,大多数解释开启远程Mysql远程服务的命令如下:
grant all privileges on *.* to 'root'@'%' identified by '你的密码' with grant option 1 这种方法并不适用于Mysql 8.0以后的版本,
需要用如下命令开启远程服务。
CREATE USER 'root'@'%' IDENTIFIED BY '你的密码'; GRANT ALL ON *.* TO 'root'@'%'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码'; 1 2 3 三条命令按顺序执行完成后,刷新权限:
FLUSH PRIVILEGES; 1 实际效果: