標籤:mysql 資料庫
1、檢測下系統有沒有內建的mysql:yum list installed | grep mysql,
如果已經有的話執行命令yum -y remove mysql-libs.x86_64卸載已經安裝的mysql。
http://dev.mysql.com/downloads/mysql/
2、先到mysql官網下載5.7.11的安裝包,download-yum選擇Red Hat Enterprise Linux 7 / Oracle Linux 7 (ArchitectureIndependent), RPM Package ,
進入系統下載安裝包:
#wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
如果新的系統還沒有wget命令的話可以先:
#yum install wget
3、添加選擇yum源:
#yum localinstallmysql57-community-release-el7-7.noarch.rpmRunning transaction 正在安裝 : mysql57-community-release-el7-7.noarch 1/1 驗證中 : mysql57-community-release-el7-7.noarch 1/1 已安裝: mysql57-community-release.noarch 0:el7-7 完畢! #yum repolist all | grep mysqlmysql-connectors-community/x86_64 MySQL Connectors Community 啟用: 21mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用mysql-tools-community/x86_64 MySQL Tools Community 啟用: 36mysql-tools-community-source MySQL Tools Community - Source 禁用mysql55-community/x86_64 MySQL 5.5 Community Server 禁用mysql55-community-source MySQL 5.5 Community Server - Sourc 禁用mysql56-community/x86_64 MySQL 5.6 Community Server 禁用mysql56-community-source MySQL 5.6 Community Server - Sourc 禁用mysql57-community/x86_64 MySQL 5.7 Community Server 啟用: 110mysql57-community-source MySQL 5.7 Community Server - Sourc 禁用
4、安裝mysql:
#yum install mysql-community-server已安裝: mysql-community-libs.x86_64 0:5.7.14-1.el7 mysql-community-libs-compat.x86_64 0:5.7.14-1.el7 mysql-community-server.x86_64 0:5.7.14-1.el7 作為依賴被安裝: mysql-community-client.x86_64 0:5.7.14-1.el7 mysql-community-common.x86_64 0:5.7.14-1.el7 替代: mariadb-libs.x86_64 1:5.5.44-2.el7.centos 完畢!
5、安裝完成之後會自動在log中產生串連的密碼,
啟動mysql:
#systemctl start mysqld
查看密碼:
[[email protected] ~]# cat /var/log/mysqld.log |grep password2016-08-23T02:33:48.872073Z 1 [Note] A temporary password isgenerated for [email protected]: %IrczkB+J7Ez
你必須重新設定密碼才能執行語句
[[email protected] ~]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.14Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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.
其實想要重設 5.7 的密碼很簡單,就一層窗戶紙:
1、修改/etc/my.cnf,在 [mysqld] 小節下添加一行:skip-grant-tables=1
這一行配置讓 mysqld 啟動時不對密碼進行驗證
2、重啟mysqld 服務:systemctl restart mysqld
3、使用 root 使用者登入到 mysql:mysql -uroot
4、切換到mysql資料庫,更新 user 表:
update user set authentication_string = password(‘123456‘),password_expired = ‘N‘, password_last_changed = now() where user = ‘root‘;
在之前的版本中,密碼欄位的欄位名是 password,5.7版本改為了 authentication_string
5、退出 mysql,編輯 /etc/my.cnf 檔案,刪除 skip-grant-tables=1的內容
6、重啟mysqld 服務,再用新密碼登入即可
[[email protected] ~]# mysql -Vmysql Ver 14.14 Distrib5.7.14, for Linux (x86_64) using EditLine wrapper
本文出自 “停止奮鬥=停止生命” 部落格,請務必保留此出處http://53cto.blog.51cto.com/9899631/1841404
CentOS7 安裝 Mysql 5.7,密碼查看與修改