1. 程式人生 > >centos7 安裝MySQL5.7中遇到的問題和解決方法

centos7 安裝MySQL5.7中遇到的問題和解決方法

centos7預設不支援mysql(原因大家都懂),預設支援的是mariadb,mariadb是mysql一個開源分支。

1、解除安裝mariadb,否則安裝mysql會出現衝突

執行命令

rpm -qa | grep mariadba

列出所有被安裝的mariadb rpm 包;

執行命令

rpm -e --nodeps 包名稱(比如:rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64)

逐個將所有列出的mariadb rpm 包給解除安裝掉

2、新增官方的yum源

以centos7安裝mysql5.7為例:

建立並編輯mysql-community.repo檔案

vi /etc/yum.repos.d/mysql-community.repo

將以下內容貼上進去並儲存

[mysql56-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

注意:gpgcheck是GPG加密校驗,官方文件中,值為1,但check會報錯誤,所以這裡改為0跳過檢查,對安裝無影響。

同理,其他centos版本安裝其他版本的mysql只需要改為對應的baseurl即可:

centos7安裝mysql5.7:baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

centos6安裝mysql5.6:baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/

centos6安裝mysql5.7:baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

3、安裝

執行命令

sudo yum install mysql-community-server

4、啟動

執行命令

sudo service mysqld start

5、改mysql 的root密碼

再修改密碼的時候會出現下列問題

解決過程:

1、編輯/etc/my.cnf

在[mysqld] 配置部分新增一行

skip-grant-tables

2、儲存後重啟mysql

[[email protected] etc]# service mysqld restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL.                                                   [  OK  ]

3、登入資料庫重新設定root密碼


[[email protected] ~]# mysql -uroot -p mysql
Enter password:

直接回車進入
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
執行下列語句
mysql>use mysql;
mysql> update user set password=password("mysql") where user='root';

新安裝的MySQL5.7,登入時提示密碼錯誤,安裝的時候並沒有更改密碼,後來通過免密碼登入的方式更改密碼,輸入update mysql.user  set password=password('root') where user='root'時提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原來是mysql資料庫下已經沒有password這個欄位了,password欄位改成了

 authentication_string

 所以更改語句替換為 update mysql.user set authentication_string=password('root') where user='root' ;

即可

最後再重新整理修改

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4、刪除/etc/my.cnf檔案中新增的“skip-grant-tables”行,重啟mysql;

用新設的密碼就能正常登入了;

centos7上安裝MySQL成功

可能是新版本的原因對MySQL的密碼要求很嚴,如果密碼太過簡單就會出現下面的問題

不管執行什麼MySQL命令都會出現下面的錯誤

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this

設定你的密碼

set password="YOUR_PASSWORD";

此時又會出現你的密碼太過簡單的錯誤提示,如果想要堅持使用簡單的命令就要改下下面兩個值的引數:

注意:如果只想設定簡單密碼需要修改兩個全域性引數:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;