1、安裝Mysqlhtml
一、查看是否安裝Mysqlnode
[root@node-41 local]# rpm -qa | grep mysqlmysql
二、若是安裝了Mariadb,可刪除sql
yum remove mysql數據庫
三、下載Mysql的repo源測試
[root@node-41 local]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmui
四、安裝Mysql的yum源spa
[root@node-41 local]# yum -y install mysql57-community-release-el7-10.noarch.rpm插件
五、檢查Mysql源是否存在code
[root@node-41 local]# yum list mysql-community-server
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile
base: mirrors.aliyun.com
extras: mirrors.aliyun.com
updates: mirrors.aliyun.com Available Packages mysql-community-server.x8664 5.7.23-1.el7 mysql57-community
六、安裝Mysql服務:
[root@node-41 local]# yum -y install mysql-community-server
Installed:
mysql-community-libs.x86_64 0:5.7.23-1.el7 mysql-community-libs-compat.x86_64 0:5.7.23-1.el7 mysql-community-server.x86_64 0:5.7.23-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.23-1.el7 mysql-community-common.x86_64 0:5.7.23-1.el7 perl.x86_64 4:5.16.3-292.el7 perl-Carp.noarch 0:1.26-244.el7
perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7
perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7
perl-Pod-Escapes.noarch 1:1.04-292.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7
perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7
perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-292.el7
perl-macros.x86_64 4:5.16.3-292.el7 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7
perl-threads-shared.x86_64 0:1.43-6.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
2、安裝成功,接着就是設置Mysql啦
一、啓動Mysql服務
[root@node-41 local]# systemctl start mysqld
二、查看Mysql狀態和設置開機啓動
[root@node-41 local]# systemctl status mysqld
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2018-08-26 11:10:30 CST; 35s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1360 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 1284 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 1362 (mysqld)
CGroup: /system.slice/mysqld.service
└─1362 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Aug 26 11:10:26 node-41 systemd[1]: Starting MySQL Server...
Aug 26 11:10:30 node-41 systemd[1]: Started MySQL Server.
[root@node-41 local]# systemctl enable mysqld
三、看到上一步中的提示說明Mysql服務已經啓動了,不過此時想要鏈接MySQL,還得找到root用戶密碼
[root@node-41 local]# grep "password" /var/log/mysqld.log
2018-08-26T03:10:27.284801Z 1 [Note] A temporary password is generated for root@localhost: 2fjy,9I!ls_Z
四、鏈接數據庫
[root@node-41 local]# mysql -uroot -p
Enter password: 「輸入上一步中的密碼」
五、修改密碼,若是不修改,這次鏈接不能作任何事
5.一、設置一個符合要求的密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
5.二、若是隻是修改成一個簡單的密碼,會報如下錯誤:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
這個其實與validate_password_policy的值有關。
validate_password_policy有如下取值:
Policy | Tests Performed |
---|---|
0 or LOW |
Length |
1 or MEDIUM |
Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG |
Length; numeric, lowercase/uppercase, and special characters; dictionary file |
默認是1,即MEDIUM,因此剛開始設置的密碼必須符合長度,且必須含有數字,小寫或大寫字母,特殊字符。
有時候,只是爲了本身測試,不想密碼設置得那麼複雜,譬如說,我只想設置root的密碼爲123456。
必須修改兩個全局參數:
首先,修改validate_password_policy參數的值:
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
這樣,判斷密碼的標準就基於密碼的長度了。這個由validate_password_length參數來決定。
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)
validate_password_length參數默認爲8,它有最小值的限制,最小值爲:
validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
其中,validate_password_number_count指定了密碼中數據的長度,validate_password_special_char_count指定了密碼中特殊字符的長度,validate_password_mixed_case_count指定了密碼中大小字母的長度。
這些參數,默認值均爲1,因此validate_password_length最小值爲4,若是你顯性指定validate_password_length的值小於4,儘管不會報錯,但validate_password_length的值將設爲4。以下所示:
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)
若是修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一個值,則validate_password_length將進行動態修改。
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)
mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
| 1 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> set global validate_password_mixed_case_count=2;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
| 2 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 6 |
+----------------------------+
1 row in set (0.00 sec)
固然,前提是validate_password插件必須已經安裝,MySQL5.7是默認安裝的。
那麼如何驗證validate_password插件是否安裝呢?可經過查看如下參數,若是沒有安裝,則輸出將爲空。
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 | 2 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
5.三、完成上述的修改後,可設置簡單密碼爲:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
六、 由於安裝了Yum Repository,之後每次yum操做都會自動更新,須要把這個卸載掉:
[root@node-41 local]# yum -y remove mysql57-community-release-el7-10.noarch
此時纔算真正的安裝成功了。