一、通過Yum命令安裝
1.下載rpm安裝源
官方地址:https://dev.mysql.com/downloads/repo/yum/
rpm文件地址:https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
1)通過wget命令下載文件
[root@localhost ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm --2018-01-08 16:57:46-- https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 正在解析主機 dev.mysql.com (dev.mysql.com)... 137.254.60.11 正在連接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已連接。 已發出 HTTP 請求,正在等待回應... 302 Found 位置:https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm [跟隨至新的 URL] --2018-01-08 16:57:48-- https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm 正在解析主機 repo.mysql.com (repo.mysql.com)... 23.1.165.122 正在連接 repo.mysql.com (repo.mysql.com)|23.1.165.122|:443... 已連接。 已發出 HTTP 請求,正在等待回應... 200 OK 長度:25680 (25K) [application/x-redhat-package-manager] 正在保存至: “mysql57-community-release-el7-11.noarch.rpm” 100%[==================================================================================================================================================================================================>] 25,680 --.-K/s 用時 0.1s 2018-01-08 16:57:48 (232 KB/s) - 已保存 “mysql57-community-release-el7-11.noarch.rpm” [25680/25680]) [root@localhost ~]#
2.安裝Mysql
1)安裝Mysql源文件
yum localinstall -y mysql57-community-release-el7-11.noarch.rpm
2)查看Mysql源是否安裝成功
[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*" mysql-connectors-community/x86_64 MySQL Connectors Community 42 mysql-tools-community/x86_64 MySQL Tools Community 55 mysql57-community/x86_64 MySQL 5.7 Community Server 227 [root@localhost ~]#
3)安裝Mysql服務
yum install -y mysql-community-server
4)查看Mysql服務是否安裝成功
[root@localhost ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html [root@localhost ~]#
3.啟動Mysql
systemctl start mysqld
4.修改root登錄密碼
1)獲取root默認密碼(由於Mysql安全策略升級,安裝完成后系統自動設置了一個隨機密碼)
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log 2018-01-08T09:21:45.780623Z 1 [Note] A temporary password is generated for root@localhost: auw;Nj7J!j/J [root@localhost ~]#
2)登錄Mysql
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20 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>
3)修改密碼
3.1)由於Mysql默認要求設置密碼復雜度高(必須包含 大小寫字母、數字、符號)
mysql> alter user 'root'@'localhost' identified by '123456'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql>
這樣設置是合法的:
mysql> alter user 'root'@'localhost' identified by 'Mysql666!'; Query OK, 0 rows affected (0.00 sec) mysql>
3.2)關閉Mysql密碼校驗規則,允許設置簡單密碼
3.2.1)在Mysql配置文件最后加入:validate_password = off
[root@localhost ~]# vi /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid validate_password = off
3.2.2)重啟Mysql服務生效
systemctl restart mysqld
4)設置簡單密碼 :)
mysql> alter user 'root'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql>
5.配置遠程用戶登錄
1)指定Ip
mysql> grant all privileges on *.* to 'root'@'192.168.1.1' identified by '123456' with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>
2)允許所有
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>
6.設置開機啟動
systemctl enable mysqld
systemctl daemon-reload
7.其他
1)已配置遠程訪問權限,依然不能登錄?請檢查系統是否開啟了防火牆。
1.1)CentOS關閉防火牆
systemctl stop firewalld.service
1.2)禁止防火牆開機啟動
systemctl disable firewalld.service
2)Mysql客戶端軟件(推薦)
2.1)SQLyog(官網:https://sqlyog.en.softonic.com/)
2.2)Navicat(官網:https://www.navicat.com/en/)
