1. 程式人生 > 其它 >【NOIP2013初賽】整除

【NOIP2013初賽】整除

Linux RPM 方式安裝 MySQL在 hadoop02機器上

1、 安裝新版mysql前,需將系統自帶的mariadb-lib解除安裝

[root@hadoop02 ~]# rpm -qa|grep mariadb     #查詢系統自帶得mariadb-lib
mariadb-libs-5.5.68-1.el7.x86_64
[root@hadoop02 ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64    #解除安裝系統自帶得mariadb-lib
[root@hadoop02 ~]# rpm -qa|grep mariadb     #檢查系統自帶得mariadb-lib是否已解除安裝

2. 官網下載5.7版本:

 

 

 

 

 

 3.可以使用xftp上傳到hadoop02機器得/opt/mysql目錄下

 4. 解壓安裝包並

[root@hadoop02 mysql]# tar -xvf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-5.7.32-1.el7.x86_64.rpm
mysql-community-common-5.7.32-1.el7.x86_64.rpm
mysql-community-devel-5.7.32-1.el7.x86_64.rpm
mysql-community-embedded-5.7.32-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.32-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.32-1.el7.x86_64.rpm
mysql-community-libs-5.7.32-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
mysql-community-server-5.7.32-1.el7.x86_64.rpm
mysql-community-test-5.7.32-1.el7.x86_64.rpm
[root@hadoop02 mysql]# ll
總用量 1060072
-rw-r--r-- 1 root root  542750720 12月 15 14:21 mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415  26460548 9月  25 12:48 mysql-community-client-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    314936 9月  25 12:48 mysql-community-common-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   3918236 9月  25 12:48 mysql-community-devel-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  47479624 9月  25 12:48 mysql-community-embedded-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  23263144 9月  25 12:48 mysql-community-embedded-compat-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 130933732 9月  25 12:48 mysql-community-embedded-devel-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2457204 9月  25 12:48 mysql-community-libs-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   1260336 9月  25 12:48 mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 181712536 9月  25 12:49 mysql-community-server-5.7.32-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 124941892 9月  25 12:49 mysql-community-test-5.7.32-1.el7.x86_64.rpm

 為了避免出現許可權問題,給mysql解壓檔案所在目錄賦予最大許可權

[root@hadoop02 opt]# chmod -R 777 mysql/
[root@hadoop02 opt]# ll
總用量 4
drwxrwxrwx  2 root root 4096 12月 15 14:23 mysql
drwxr-xr-x. 2 root root    6 10月 31 2018 rh

嚴格按照順序安裝:mysql-community-common-5.7.29-1.el7.x86_64.rpm、mysql-community-libs-5.7.29-1.el7.x86_64.rpm、mysql-community-client-5.7.29-1.el7.x86_64.rpm、mysql-community-server-5.7.29-1.el7.x86_64.rpm這四個包

rpm -ivh mysql-community-common-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.32-1.el7.x86_64.rpm

5. 配置資料庫

vim /etc/my.cnf

新增這三行

skip-grant-tables:跳過登入驗證

character_set_server=utf8:設定預設字符集UTF-8

init_connect='SET NAMES utf8':設定預設字符集UTF-8

 

 

 6 . 啟動mysql服務

[root@hadoop02 mysql]# systemctl start mysqld.service  #設定開機啟動
[root@hadoop02 mysql]# mysql    #啟動mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32 MySQL Community Server (GPL)

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>

7. 設定密碼和開啟遠端登入

設定一個簡單的密碼

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並停止mysql服務

mysql> quit;
Bye
[root@hadoop02 mysql]# systemctl stop mysqld.service

編輯/etc/my.cnf配置檔案將:skip-grant-tables這一行註釋掉 ,並重啟mysql服務

[root@hadoop02 mysql]# vim /etc/my.cnf
[root@hadoop02 mysql]# systemctl start mysqld.service

再次登入mysql

[root@hadoop02 mysql]# mysql -uroot -p123456

重新重設密碼

ALTER USER USER() IDENTIFIED BY '123456';

如果出現如下錯誤:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
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 | 6 |              #固定密碼的總長度;
| validate_password_mixed_case_count | 1 |    # 整個密碼中至少要包含大/小寫字母的總個數
| validate_password_number_count | 1 |        #整個密碼中至少要包含阿拉伯數字的個數
| validate_password_policy | LOW |            #指定密碼的強度驗證等級,預設為 MEDIUM
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+

設定密碼的驗證強度等級,設定 validate_password_policy 的全域性引數為 LOW

set global validate_password_policy=LOW;  #只驗證密碼得長度
set global validate_password_length=6;   #密碼驗證得長度修改成功

開啟mysql遠端訪問

grant all privileges on *.* to 'root'@'%' identified by '123123' with grant option;

 by後面的就是遠端登入密碼,遠端登入密碼可以和使用者密碼不一樣