博主信息
博文 65
粉丝 1
评论 1
访问量 134735
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
初次安装mysql 设置密码
技术宅的博客
原创
1919人浏览过

首先 打开配置文件  vim /etc/my.cnf
并在[mysql]下面加上 

skip-grant-tables

然后重启mysql  

service mysqld restatus  #重启

更新密码

UPDATE user SET Password=PASSWORD('newpassword') where USER='root';   
#最新mysql
UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
#如果提示user 不存在 就替换为  mysql.user
刷新
FLUSH PRIVILEGES;
退出
quit;

如下所示

mysql> UPDATE user SET authentication_string=PASSWORD('123456') where USER='root';

ERROR 1046 (3D000): No database selected

mysql> UPDATE mysql.user SET authentication_string=PASSWORD('123456') where USER='root';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 1

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.01 sec)

mysql> quit;

出现如下问题

mysql> show databases;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> 

mysql> show databases;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by '123456';

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

解决办法

vim /etc/my.cnf

在文件末尾添加以下内容:

plugin-load=validate_password.so

validate-password=OFF


# For advice on how to change settings please see

# http://dev.mysql***/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]

#

# 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

#skip-grant-tables

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

plugin-load=validate_password.so

validate-password=OFF



重启  service mysqld restart

mysql> alter user 'root'@'localhost' identified by '123456';

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

mysql> exit;

 由此便解决了

本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学