博客列表 >初次安装mysql 设置密码

初次安装mysql 设置密码

技术宅的博客
技术宅的博客原创
2019年08月14日 21:20:321689浏览

首先 打开配置文件  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 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议