1. 程式人生 > >mysql5.7版本yum安裝---redhat7.0

mysql5.7版本yum安裝---redhat7.0

1.官網下載yum包

 [[email protected] test]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm  ./

2.安裝mysql依賴包

[[email protected] test]# ls
mysql57-community-release-el7-10.noarch.rpm
[[email protected] test]# yum install -y mysql57-community-release-el7-10.noarch.rpm

3.安裝mysql

[[email protected] test]# yum install -y mysql-community-server.x86_64 

4.啟動mysql服務

[[email protected] test]# systemctl start mysqld.service 

mysql伺服器初次啟動時,會有一個初始化過程,給伺服器一個空的資料目錄(data)

  1.伺服器被初始化

  2.在資料目錄中生成SSL證書和金鑰檔案

  3.安裝validate_password外掛並啟動

  4.建立超級使用者“root”@“localhost”,密碼被設定並且儲存在錯誤日誌檔案中

5.在錯誤日誌中找出密碼並進入伺服器修改密碼

[[email protected] test]# grep 'temporary password' /var/log/mysqld.log

找出密碼後直接登入伺服器,修改密碼

[[email protected] test]# mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'redhat';

密碼若太過簡單會報錯

也可以執行mysql_secure_installation程式來修改密碼,不過官網上建議5.7及以上版本不建議執行這個程式,因為這個程式的功能已經被yum儲存倉庫安裝完成

mysql_secure_installation — Improve MySQL Installation Security for details. 
Do not run mysql_secure_installation after an installation of MySQL 5.7 or higher, as the function of the program has already been performed by the Yum repository installation. 

還有一種方法是編輯mysql的配置檔案 my.cnf 在 [mysqld]下新增一行skip-grant-tables,重啟服務

[[email protected] test]# vim /etc/my.cnf
[[email protected] test]# systemctl restart mysqld.service 
[[email protected] test]# mysql -uroot
mysql> use mysql    ==>使用mysql資料庫
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD('redhat') where user='root'; ==>修改user表的資料,修改使用者root的密碼
Query OK, 0 rows affected, 1 warning (0.11 sec)
Rows matched: 4  Changed: 0  Warnings: 1

mysql> flush privileges;    ==>重新整理許可權表
Query OK, 0 rows affected (0.07 sec)

退出資料庫,在編輯配置檔案my.cnf,刪除新增的那一行

mysql> exit
Bye
[[email protected] test]# vim /etc/my.cnf
[[email protected] test]# systemctl restart mysqld.service 
[[email protected] test]# mysql -uroot -predhat
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 2
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> 

可以正常登入了

6.設定開機自啟

[[email protected] test]# systemctl enable mysqld.service