Blogger Information
Blog 65
fans 1
comment 1
visits 118878
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
初次安装mysql 设置密码
技术宅的博客
Original
1690 people have browsed it

首先 打开配置文件  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;

 由此便解决了

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post