centos修改MysqL密码或者
进入MysqL后解决Access denied for user ”@’localhost’ to database ‘MysqL错误
原因是MysqL的密码有问题
用MysqL匿名用户可以进入数据库,但是看不见MysqL数据库.
解决办法:
具体操作步骤:
关闭MysqL:
service MysqLd stop
然后:
MysqLd_safe –skip-grant-tables
开启另一个终端并启动MysqL:
service MysqLd start
MysqL -u root
MysqL> use MysqL
MysqL> UPDATE user SET Password=PASSWORD(‘root’) WHERE user=’root’;
MysqL> flush privileges;
MysqL>\q
到这里密码已经修改成功,
MysqL -u root -p
提示:ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘MysqL’。前两天也出现过这个问题,网上找了一个比较流行的方法(见方法一),搞定了。今天又用这个试了试,却搞不定,在网上找了半天,终于发现是因为MysqL数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的”@’localhost’可以看出来,于是解决办法见方法二。
方法一:
1.关闭MysqL
# service MysqLd stop
2.屏蔽权限
# MysqLd_safe –skip-grant-table
屏幕出现: Starting demo from …..
3.新开起一个终端输入
# MysqL -u root MysqL
MysqL> UPDATE user SET Password=PASSWORD(‘newpassword’) where USER=’root’;
MysqL> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
MysqL> \q
方法二:
1.关闭MysqL
# service MysqLd stop
2.屏蔽权限
# MysqLd_safe –skip-grant-table
屏幕出现: Starting demo from …..
3.新开起一个终端输入
# MysqL -u root MysqL
MysqL> delete from user where USER=”;
MysqL> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
MysqL> \q
skip_grant_tables改为skip_grant_tables保存后,重启MysqL服务,然后改密码和删除user=”的记录
# For advice on how to change settings please see
# http://dev.MysqL.com/doc/refman/5.6/en/server-configuration-defaults.html
[MysqLd]
character-set-server=utf8
#bind-address=0.0.0.0
port=3306
#skip_grant_tables
max_connections=200
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MysqL. Start at 70% of total RAM for dedicated server,else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed,experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MysqL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[MysqLd_safe]
log-error=/var/log/MysqLd.log
pid-file=/var/run/MysqLd/MysqLd.pid
MysqL账户是否不允许远程连接。如果无法连接可以尝试以下方法:
MysqL -u root -p //登录MysqL
MysqL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; //任何远程主机都可以访问数据库
MysqL> FLUSH PRIVILEGES; //需要输入次命令使修改生效
MysqL> EXIT //退出
也可以通过修改表来实现远程:
MysqL -u root -p
MysqL> use MysqL;
MysqL> update user set host = '%' where user = 'root';
MysqL> select host,user from user;