mysql密码相关

Q1: root密码登录不了或忘记root密码

Answer: 在mysql配置文件(my.cnf / base.cnf)中[mysqld]下添加一行 skip_grant_tables,然后重启mysql,root用户即可无密码登录,然后设置新密码(详见Q2/Q3),再删除skip_grant_tables并重启mysql。

***********************************************************************
## v1.0 root@karl-v1:/srv/leyao/main# cat conf.d/base.cnf [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci query_cache_size = 64M query_cache_type = 1 join_buffer_size = 512K max_connections = 150 max_allowed_packet = 32M skip_grant_tables root@karl-v1:/srv/leyao/main#
************************************************************************* # v2.
0 karl-v2 docker # cat mysql/my.cnf # The MySQL Client configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysql] [mysqld] sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" character-set-server=utf8 max_allowed_packet=1048576 skip_grant_tables karl-v2 docker #

 

 

Q2: 设置/修改root密码(v1.0)

use mysql;
update user set password=password("new_pwd") where user='root';
flush privileges;
update user set authentication_string=password('t4ecK@^y7I4CGJnwtajWuKDmAwktngth') where user='root'; #new try

 

 

Q3: 设置/修改root密码(v2.0)

use mysql;
alter user 'root'@'%' identified by 'new_pwd';
flush privileges;

 

posted on 2019-05-15 09:52  Karlkiller  阅读(98)  评论(0编辑  收藏  举报

导航