___
来到数据库安装目录下面,修改my.cnf文件
vi my.cnf
添加 skip-grant-tables,或者给注释打开.
然后来到安装根目录下,重启mysql, ./mysql restart
来到bin目录下, 就可以免密登录数据库了.
./mysql -uroot -p -S ../data/dxp.sock
进入之后就可以修改密码了.
查阅后才知道在mysql 5.7.9以后废弃了password字段和password()函数;authentication_string:字段表示用户密码,而authentication_string字段下只能是mysql加密后的41位字符串密码。所以需要用一下方式来修改root密码.
user表加了字段authentication_string,修改密码前先检查authentication_string是否为空
1、如果不为空
use mysql;
update user set authentication_string='' where user='root';--将字段置为空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root
如果为空,直接修改
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root
如果出现如下错误
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
需要执行
flush privileges;
然后再执行
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root
改完之后记得给安装目录下的配置文件my.cnf的skip-grant-tables
注释掉.
查看mysql版本: bin/mysql -V, 安装目录下面的mysql负责启动与停止命令,bin下面的mysql文件用来进入mysql,查看版本.