溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CentOS7安裝Mysql5.7怎么查看與修改密碼

發(fā)布時間:2022-04-07 16:31:21 來源:億速云 閱讀:650 作者:iii 欄目:編程語言

本文小編為大家詳細(xì)介紹“CentOS7安裝Mysql5.7怎么查看與修改密碼”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“CentOS7安裝Mysql5.7怎么查看與修改密碼”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識吧。

軟件版本

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

檢測下系統(tǒng)有沒有自帶的mysql:yum list installed | grep mysql

如果已經(jīng)有的話執(zhí)行命令 yum -y remove mysql-libs.x86_64 卸載已經(jīng)安裝的 MySQL 。

安裝

使用 rpm 包進(jìn)行mysql服務(wù)器的安裝

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 "temporary password" /var/log/mysqld.log 命令查看生成的密碼。

初次登錄MySQL客戶端必須重新設(shè)置密碼才能進(jìn)行數(shù)據(jù)的操作,如下:

[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.

密碼設(shè)置

不過需要注意的是現(xiàn)在MySQL已經(jīng)強制要求強密碼,已經(jīng)不能再用弱密碼比如“123456”了。如果你設(shè)置的密碼過于簡單,會提示錯誤:

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

set password 命令

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

mysqladmin 命令

mysqladmin -u root password "newpass" # 如果root沒有設(shè)置密碼使用這種方式
mysqladmin -u root password oldpass "newpass" # 如果root設(shè)置了密碼使用這種方式

使用 update 語句

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;

密碼復(fù)雜度的修改

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個字符長。

  • MEDIUM政策的條件 密碼必須包含至少1數(shù)字字符,1 大寫和小寫字符,和1特別 (nonalphanumeric)字符。

  • STRONG政策的情況 密碼子字符串長度為4的或更長時間不能匹配 單詞在字典文件中,如果一個人被指定。

再進(jìn)行密碼的修改試試。

讀到這里,這篇“CentOS7安裝Mysql5.7怎么查看與修改密碼”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI