1. 程式人生 > >Linux CentOS 7.0線上安裝MySQL 5.7版本

Linux CentOS 7.0線上安裝MySQL 5.7版本

1、配置YUM源

在MySQL官網中下載YUM源rpm安裝包:http://dev.mysql.com/downloads/repo/yum/

在這裡插入圖片描述

下載mysql源安裝包

shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

安裝mysql源

shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm

檢查mysql源是否安裝成功

shell> yum repolist enabled | grep "mysql.*-community.*"

可以修改vim /etc/yum.repos.d/mysql-community.repo源,改變預設安裝的mysql版本。比如要安裝5.6版本,將5.7源的enabled=1改成enabled=0。然後再將5.6源的enabled=0改成enabled=1即可

2、安裝MySQL

shell> yum install mysql-community-server

3、啟動MySQL服務

shell> systemctl start mysqld

檢視MySQL的啟動狀態

shell> systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
 Main PID: 2888 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...
6月 24 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.

4、開機啟動

shell> systemctl enable mysqld
shell> systemctl daemon-reload

5 執行MySQL

 shell>  service mysqld start

獲取初始密碼

grep "password" /var/log/mysqld.log
#### 下面是返回的內容,密碼也末尾
2018-09-30 T08:06:46.998346Z 1 [Note] A temporary password is generated for [email protected]: y3h2rpgryw.E

修改密碼

使用臨時密碼登陸

mysql -u root -p
 ##由於 5.7 處於安全考慮,不讓設定簡單密碼,要先更改其密碼機制
set global validate_password_policy=LOW;
## 設定密碼長度
set global validate_password_length=6;
## 修改密碼
SET PASSWORD = PASSWORD('111111');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;

遠端和本地訪問

use mysql;
update user set host = '%' where user = 'root';
## 使配置生效
flush privileges;

設定字符集

## 登陸資料庫後
set character_set_database=utf8;
flush privileges;