centos7 下安裝rpm的mysql 5.7


在centos7下安裝mysql5.7

一:下載mysql 去官網上去下載;這里我下載的二進制格式的

         https://dev.mysql.com/downloads/mysql/ 去下載對應平台的mysql版本

 

二:解壓mysql並采用yum安裝本地rpm方式

[root@xuegod63 ~]# unzip mysql5.7.zip 
Archive:  mysql5.7.zip
  inflating: mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-server-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-client-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-common-5.7.20-1.el7.x86_64.rpm  
  inflating: mysql-community-libs-5.7.20-1.el7.x86_64.rpm  
[root@xuegod63 ~]# yum -y localinstall ./*.rpm 

 

三:啟動mysql服務 並查看是否啟動成功;看到有3306就代表啟動成功

[root@xuegod63 ~]# systemctl start mysqld
[root@xuegod63 ~]# ss -tnl
State       Recv-Q Send-Q                                      Local Address:Port                                                     Peer Address:Port              
LISTEN      0      128                                                     *:22                                                                  *:*                  
LISTEN      0      100                                             127.0.0.1:25                                                                  *:*                  
LISTEN      0      128                                                    :::22                                                                 :::*                  
LISTEN      0      100                                                   ::1:25                                                                 :::*                  
LISTEN 0 80 :::3306 :::*     

 

四:啟動mysql 報錯解決mysql密碼問題  

這時候可以看見是失敗的;因為mysql5.7默認是不可以直接登錄的;這里我們給出了兩種解決方式:

4.1:第一種解決mysql5.7初啟動密碼問題

[root@xuegod63 ~]# grep "password" /var/log/mysqld.log 
2017-12-12T11:07:34.808179Z 1 [Note] A temporary 
password is generated for root@localhost: %aqY==#QD7+s 這是臨時獲取的密碼等會 登錄使用 2017-12-12T11:09:50.817347Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO) [root@xuegod63 ~]# mysql -uroot -hlocalhost -p%aqY==#QD7+s
[這里要不能登錄的話就 mysql -uroot -hlocalhost -p 去手動輸入密碼] mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor.
Commands end with ; or \g. Your MySQL connection id is 4 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>


  

第一次通過# grep "password" /var/log/mysqld.log 命令獲取MySQL的臨時密碼
用該密碼登錄到服務端后,必須馬上修改密碼,不然操作查詢時報錯誤
剛開始設置的密碼必須符合長度,且必須含有數字,小寫或大寫字母,特殊字符。
如果想設置簡單密碼,如下操作:
方法一:首先,修改validate_password_policy參數的值
mysql> set global validate_password_policy=0; #定義復雜度
mysql> set global validate_password_length=1; #定義長度 默認是8
mysql>set password for 'root'@'localhost'=password('123456');

方法二:在/etc/my.cnf 可關閉密碼強度審計插件,重啟mysql服務
validate-password=ON/OFF/FORCE/FORCE_PLUS_PERMANENT: 決定是否使用該插件(及強制/永久強制使用)。

 

4.2:第二種解決mysql5.7初啟動密碼問題

MySQL5.7的跳過授權表登錄。mysql啟動時跳過授權表,使用無密碼登陸,在這個會話中再把授權表加載進來,把密碼修改之后重啟即可。
1.關閉MySQL數據庫
[root@localhost ~]# systemctl stop mysqld
Redirecting to /bin/systemctl stop mysqld.service
[root@localhost ~]# mysqld --help
[root@localhost ~]# mysqld --verbose --help >a.txt
加上--skip-grant-tables這個參數重啟時,便可以跳過密碼驗證這個參數。
--skip-grant-tables (Start without grant tables. This gives all users FULL ACCESS to all tables.)
2.進入/etc/my.cnf配置文件把 validate_password=off參數注釋掉。(如果有的話)
3.先執行
[root@localhost ~]# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
([root@localhost ~]# mysqld_safe --skip-grant-tables & 當此命令沒有時使用上面的命令)
[root@localhost ~]# systemctl start mysqld 來啟動數據庫。
4.查看數據庫是否啟動 netstat -tunlp | grep 3306
5.使用mysql -u root 直接進行登陸
6.等進去之后執行 mysql> flush PRIVILEGES;
7.重新設置密碼 mysql> alter user 'root'@'localhost' identified by '1234567';
8.執行 mysql> flush tables; 並推出
9.重啟mysql的服務並登陸

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM