redhat 7下rpm安裝mysql5.7

1、根據自己需要下載相應包

https://downloads.mysql.com/archives/community/

 2、清理環境已經安裝的mysql/mariadb

rpm -qa | grep mariadb

rpm -qa | grep mysql

rpm -e --nodeps 包名

yum remove 包名

3、使用命令rpm -ivh {-file-name}進行安裝操作。

按照依賴關係依次安裝rpm包 依賴關係依次爲common→libs→client→server

[root@DZSWJfwhnm tools]# yum install libaio -y  #先安裝server的依賴
[root@DZSWJfwhnm tools]# ll -ha
total 1.1G
drwxr-x---. 2 root    root    4.0K May 18 16:48 .
drwxr-xr-x. 4 root    root      32 May 18 02:04 ..
-rw-r--r--. 1 monitor monitor 521M May 18 16:08 mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1    7155   31415  27M Dec 19 16:12 mysql-community-client-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415 312K Dec 19 16:12 mysql-community-common-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415 3.9M Dec 19 16:12 mysql-community-devel-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415  46M Dec 19 16:12 mysql-community-embedded-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415  23M Dec 19 16:12 mysql-community-embedded-compat-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415 125M Dec 19 16:12 mysql-community-embedded-devel-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415 2.5M Dec 19 16:12 mysql-community-libs-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415 1.3M Dec 19 16:12 mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415 176M Dec 19 16:12 mysql-community-server-5.7.29-1.el7.x86_64.rpm
-rw-r--r--. 1    7155   31415 119M Dec 19 16:12 mysql-community-test-5.7.29-1.el7.x86_64.rpm
[root@DZSWJfwhnm tools]# rpm -qa | grep mysql
[root@DZSWJfwhnm tools]# rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@DZSWJfwhnm tools]# rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
[root@DZSWJfwhnm tools]# rpm -qa | grep mariadb
[root@DZSWJfwhnm tools]# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.29-1.e################################# [100%]
[root@DZSWJfwhnm tools]# rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.29-1.el7################################# [100%]
[root@DZSWJfwhnm tools]# rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.29-1.e################################# [100%]
[root@DZSWJfwhnm tools]# rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.29-1.e################################# [100%]
[root@DZSWJfwhnm tools]#

安裝完mysql-community-server-5.7.29-1.el7.x86_64.rpm後會創建如下文件及文件夾

/etc/my.cnf
/etc/my.cnf.d/
/var/lib/mysql/
/var/lib/mysql-files/
/var/lib/mysql-keyring/
/var/run/mysqld/

my.cnf裏面涉及目錄都手動創建和授權mysql,

systemctl start mysqld啓動,會自動初始化,如果先執行了mysqld --initialize初始化,需要到指定的datadir裏面的把文件刪掉再啓

[root@DZSWJfwhnm mysql]# grep -v "#" /etc/my.cnf

[mysqld]
datadir=/software/mysql/sjswh
character-set-server=utf8
max_connections=1024
lower_case_table_names=1

socket=/var/lib/mysql/mysql.sock

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@DZSWJfwhnm mysql]# systemctl start mysqld
[root@DZSWJfwhnm mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-05-19 14:50:13 CST; 5min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 19064 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 19009 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 19067 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           └─19067 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

May 19 14:50:07 DZSWJfwhnm systemd[1]: Starting MySQL Server...
May 19 14:50:13 DZSWJfwhnm systemd[1]: Started MySQL Server.
[root@DZSWJfwhnm mysql]# ps -ef | grep mysql
mysql    19067     1  0 14:50 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

 

[root@DZSWJfwhnm mysql]# tail -f /var/log/mysqld.log #從日誌看到產生了一個root隨機初始密碼
2020-05-19T06:50:13.380352Z 0 [Note] Event Scheduler: Loaded 0 events
2020-05-19T06:50:13.381234Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.29'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
2020-05-19T06:54:04.322241Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-19T06:54:04.697386Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-19T06:54:04.809024Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-19T06:54:04.879255Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8766b726-999d-11ea-99d5-005056ba7627.
2020-05-19T06:54:04.880843Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-19T06:54:07.707333Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-19T06:54:08.383874Z 1 [Note] A temporary password is generated for root@localhost: Gkx3<k7mwu_a
[root@DZSWJfwhnm software]# mysql -uroot -p   #登錄
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, 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> alter user user() identified by "密碼";  #第一次登錄提示需要改密碼
Query OK, 0 rows affected (0.02 sec)

試下建庫和用戶

mysql> create database `m_tax` default charset utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| m_tax              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
mysql> grant all privileges on m_tax.* to m_tax@"%" identified by 'm_abc';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> show variables like 'validate_password%'; #查下密碼策略,上面報錯不符合要求
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | OFF    |
| validate_password_dictionary_file    |        |
| validate_password_length             | 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.00 sec)
mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'validate_password%';  #這裏設全局密碼強度爲LOW和位數4做下實驗
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 4     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
mysql> grant all privileges on m_tax.* to m_tax@"%" identified by 'm_abc';
Query OK, 0 rows affected, 1 warning (0.00 sec)  #可以設置簡單密碼了,生產環境不建議這樣
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

關於 mysql 密碼策略相關參數;
1、validate_password_length  固定密碼的總長度;
2、validate_password_dictionary_file 指定密碼驗證的文件路徑;
3、validate_password_mixed_case_count  整個密碼中至少要包含大/小寫字母的總個數;
4、validate_password_number_count  整個密碼中至少要包含阿拉伯數字的個數;
5、validate_password_policy 指定密碼的強度驗證等級,默認爲 MEDIUM;
關於 validate_password_policy 的取值:
LOW:只驗證長度;
MEDIUM:驗證長度、數字、大小寫、特殊字符;
STRONG:驗證長度、數字、大小寫、特殊字符、字典文件;
6、validate_password_special_char_count 整個密碼中至少要包含特殊字符的個數;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章