CentOS7安装Mysql 5.7查看和修改密码
软件版本
CentOS release 6.9 (Final) mysql Client Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper mysql Server 5.7.18
检查是否安装了MySQLServer
检查系统是否有自己的mysql:安装了yum list | grep mysql
如果已经存在运行命令yum -y remove mysql-libs.x86_64
删除已安装的MySQL。
安装
使用rpm包安装mysql服务器。特别下载地址为:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
wget http://repo.mysql.com/yum/mysql-5.7-community/el/6/x86_64/mysql-community-server-5.7.18-1.el6.x86_64.rpm rpm -ivh mysql-community-server-5.7.18-1.el6.x86_64.rpm
启动
service mysqld start
查看密码
安装完成后会自动生成连接密码在 /var/log/mysqld.log
。使用命令grep "temp password" /var/log/mysqld.log
查看。密码已创建。
首次登录MySQL客户端时,需要重置密码才能进行数据操作,如下:
[root@localhost src]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.18 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
设置密码
不过需要注意的是,现在MySQL需要强密码,弱密码如“123456”,不能再使用。 “是的。如果您设置的密码太简单,会出现错误消息:
ERROR 1819 (HY000): 您的密码不符合当前策略要求
设置密码
命令
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
mysqladmin
命令
mysqladmin -u root password "newpass" # 如果root没有设置密码使用这种方式 mysqladmin -u root password oldpass "newpass" # 如果root设置了密码使用这种方式
使用语句 更新
UPDATE user SET authentication_string = PASSWORD('newpass') WHERE user = 'root';
忘记密码
mysqld_safe --skip-grant-tables& mysql -u root mysql mysql> UPDATE user SET authentication_string=PASSWORD("new password") WHERE user='root'; mysql> FLUSH PRIVILEGES;
更改密码复杂性
mysql> show variables like "validate_password%"; +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | # 必须8个字符以上 | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | # 具体看下面的配置 | validate_password_special_char_count | 1 | +--------------------------------------+--------+ 7 rows in set (0.01 sec) mysql> SET GLOBAL validate_password_policy='LOW'; Query OK, 0 rows affected (0.00 sec) mysql> SET GLOBAL validate_password_length = 6; Query OK, 0 rows affected (0.00 sec)
LOW
策略仅测试密码长度 密码长度必须至少为 8 个字符 条款 中 创建用户并授权CREATE USER 'test'@'%' IDENTIFIED BY 'password'; GRANT ALL ON test.* TO 'test'@'%' WITH GRANT OPTION;
版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。