linux连接mysql /usr/local/mysql/bin/mysql -uroot -p
输入密码出现Access denied for user 'root'@'localhost'(using password: YES)错误。
解决办法:
1.先停止mysql 服务
service mysqld stop
2.进入mysql安装目录bin/ 使用safe模式,进行重启:
./mysqld_safe --skip-grant-tables
3.新开一个终端,使用root账户,无密码登录,修改root用户密码
/usr/local/mysql/bin/mysql -uroot
use mysql
update user set password=PASSWORD("你的密码") where User = 'root';
5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
update user set authentication_string=PASSWORD("你的密码") where User = 'root';
4.重启mysql,正常登录
service mysqld restart 重启
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhwAAAA7CAYAAAAwyFPbAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAA2jSURBVHhe7Z1tkuO4DYbnPHMVXyROpSqp3WSz2fntg/gcc7gOQREiCAIgpZa6rem3pp6aFj8B0hJeURb97cePH2/fvn27DrfH28+fPxeed7sM2M/3+9vzccvj/Lx/t8sAAAAAW7EEx/f7swT159v9e5v3qVAwFDbdHj/fHrf690fZS30dHYy32L+//9vbo4g1t34RHPQZ4LG9GmfMzxWo5+2M/+WzANEOAPgoPMHxWRfs+/PxdjPSic4udRd+f76YQNrIR9kfzi+tIF1ccHx15s/fJDpeTHBE5/8RnN0+ACBgi+C4P+vdE5VZ7qbaE5jLWHlhfl69kHkLMujdHhyQ7Tv1HLBvsp0+gEf2jfyraf4dZNN+sue54YI+sj/qn/MeD/HIyRh/LmvZv6yyKDYGpNB/Pceq7Wj8pW3ZduPR2sz8ND6meo3IG9jnwvVSW8vnMtm82lfmYG279rfaK/oZfX5k/uNmr1J486v9y/VnfUxE85PLTIyf65+uW2hEr5zzhPYxtG+mfQDAufy1dYWDT3q+UKRjPmnphG/qUVlx0RnlL2XEBUzBgoOCRu4z1ZftLRccHUBqezP95zTHP8YbH52eg5tuP2BkPxP1LwPArJ0NZUyruJtn5L9ewcn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IOK/VxMccj+Kg98yAQnejGzrq70QHAAAACIswfGyr+00r422234vr6R+jL16R9Aj2GL//v4nXlsqgoM+A5te64XgAAAAEGE9UvnMjUmi3x/p7FJ34Xrr8qvxUfaH80srSBAcAAAAjsb60qgXkHjTLMqjMssqSCsQmo21jE2r3Pxmq/CKDHr1d0TsO/UcsG+ynT6AR/aN/Ktp/gpB0z5tnb7hsc/I/qh/zns85Bbo/fhzWcv+ZZVFMWs/BAcAAIAIax8OLyBl+DsUHIjSMYsCCrZNPSorAtYofyljB0mCBQcFxtxnqi/bW4K9CNJZxNT2ZvrPaY5/jDc+Oj0HcN1+wMh+JupfC6QZOxvKmG7+GXwIDgAAABHW1uYzAalLL8/+dfoauEb55XhGcKyPHpQtFLAtcZDTJvt3/RP441NXXhZ8XyxC+1Wa1X9X1vHFt7/mQXAAAAA4lH/8dT3BkdvioN6soPRBcg3CHyI4FKmtbSscgf0qzeq/K7tJcGixtDDlJwHBAQAAIOLvfx4kOBJ9wExBLBQEbX5XhgL2xCMCJj+SkO1lYVLrz/T/HsHRtU/2GyLHY2Q/4/VP6UescFAbkfAzgeAAAAAQcf9jVnDYd8BNgJMrD3vyiSwyOF8FvU5A1Pr8WunjUb9Y2X1pNOx/5J+dL23MgsHJGzG2P+6f5ozTss1iHPVcRoKDV3wgOAAAABzK36YFx2sgA+uW1QNQGQsOY+VnBAQHAACACG+FYwnqaoUAXJy6SnK4oITgAAAA4PLt7f80R7xasFaQIAAAAABJRU5ErkJggg==" alt="" />
/usr/local/mysql/bin/mysql -uroot -p 然后输入刚才重置的密码
完成,连接成功!