主頁 > 知識(shí)庫 > Centos MySQL 5.7安裝、升級(jí)教程

Centos MySQL 5.7安裝、升級(jí)教程

熱門標(biāo)簽:清遠(yuǎn)申請(qǐng)400電話 東莞外呼企業(yè)管理系統(tǒng) 南通電銷外呼系統(tǒng)哪家強(qiáng) 谷歌地圖標(biāo)注位置圖解 沈陽智能外呼系統(tǒng)供應(yīng)商 桂林云電銷機(jī)器人收費(fèi) 如何選擇優(yōu)質(zhì)的外呼系統(tǒng) 手機(jī)外呼系統(tǒng)違法嗎 地圖簡(jiǎn)圖標(biāo)注

MySQL 5.7安裝、升級(jí)筆記分享:

卸載當(dāng)前的 MySQL

查看當(dāng)前 MySQL 版本:

[root@coderknock ~]# mysql -V
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (i386) using readline 5.1

停止 MySQL 服務(wù)

[root@coderknock ~]# service mysqld stop
Stopping mysqld:      [ OK ]

備份數(shù)據(jù)【數(shù)據(jù)不重要可以忽略】

備份數(shù)據(jù)庫,升級(jí)MySQL通常不會(huì)丟失數(shù)據(jù),但保險(xiǎn)起見,我們需要做這一步。輸入命令:

[root@coderknock ~]# mysqldump -u xxx -h xxx -P 3306 -p --all-databases > databases.sql

卸載舊版本 MySQL

[root@coderknock ~]# yum remove mysql mysql-*
Loaded plugins: security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.i686 0:5.1.73-7.el6 will be erased
---> Package mysql-libs.i686 0:5.1.73-7.el6 will be erased
--> Processing Dependency: libmysqlclient.so.16 for package: 2:postfix-2.6.6-6.el6_7.1.i686
--> Processing Dependency: libmysqlclient.so.16 for package: perl-DBD-MySQL-4.013-3.el6.i686
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16) for package: 2:postfix-2.6.6-6.el6_7.1.i686
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16) for package: perl-DBD-MySQL-4.013-3.el6.i686
--> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-6.el6_7.1.i686
---> Package mysql-server.i686 0:5.1.73-7.el6 will be erased
--> Running transaction check
---> Package perl-DBD-MySQL.i686 0:4.013-3.el6 will be erased
---> Package postfix.i686 2:2.6.6-6.el6_7.1 will be erased
--> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-16.el6_8.2.i686
--> Processing Dependency: /usr/sbin/sendmail for package: redhat-lsb-core-4.0-7.el6.centos.i686
--> Running transaction check
---> Package cronie.i686 0:1.4.4-16.el6_8.2 will be erased
--> Processing Dependency: cronie = 1.4.4-16.el6_8.2 for package: cronie-anacron-1.4.4-16.el6_8.2.i686
---> Package redhat-lsb-core.i686 0:4.0-7.el6.centos will be erased
--> Running transaction check
---> Package cronie-anacron.i686 0:1.4.4-16.el6_8.2 will be erased
--> Processing Dependency: /etc/cron.d for package: crontabs-1.10-33.el6.noarch
--> Processing Dependency: /etc/cron.d for package: sysstat-9.0.4-31.el6.i686
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package crontabs.noarch 0:1.10-33.el6 will be erased
---> Package sysstat.i686 0:9.0.4-31.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================
 Package     Arch    Version     Repository        Size
=======================================================================================================================================================================================================
Removing:
 mysql     i686    5.1.73-7.el6     @base        2.3 M
 mysql-libs     i686    5.1.73-7.el6     @base        3.9 M
 mysql-server    i686    5.1.73-7.el6     @base        24 M
Removing for dependencies:
 cronie     i686    1.4.4-16.el6_8.2    @updates        169 k
 cronie-anacron    i686    1.4.4-16.el6_8.2    @updates        38 k
 crontabs     noarch    1.10-33.el6     @anaconda-CentOS-201311291201.i386/6.5    2.4 k
 perl-DBD-MySQL    i686    4.013-3.el6     @base        341 k
 postfix     i686    2:2.6.6-6.el6_7.1    @base        9.3 M
 redhat-lsb-core    i686    4.0-7.el6.centos    @anaconda-CentOS-201311291201.i386/6.5    22 k
 sysstat     i686    9.0.4-31.el6     @base        804 k

Transaction Summary
=======================================================================================================================================================================================================
Remove 10 Package(s)

Installed size: 41 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Erasing : mysql-server-5.1.73-7.el6.i686                   1/10 
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
 Erasing : redhat-lsb-core-4.0-7.el6.centos.i686                  2/10 
/var/tmp/rpm-tmp.Y5QGjy: line 1: lsb_release: command not found
 Erasing : mysql-5.1.73-7.el6.i686                    3/10 
 Erasing : perl-DBD-MySQL-4.013-3.el6.i686                   4/10 
 Erasing : sysstat-9.0.4-31.el6.i686                    5/10 
 Erasing : crontabs-1.10-33.el6.noarch                   6/10 
 Erasing : cronie-anacron-1.4.4-16.el6_8.2.i686                  7/10 
 Erasing : cronie-1.4.4-16.el6_8.2.i686                   8/10 
 Erasing : 2:postfix-2.6.6-6.el6_7.1.i686                   9/10 
 Erasing : mysql-libs-5.1.73-7.el6.i686                   10/10 
 Verifying : redhat-lsb-core-4.0-7.el6.centos.i686                  1/10 
 Verifying : perl-DBD-MySQL-4.013-3.el6.i686                   2/10 
 Verifying : mysql-server-5.1.73-7.el6.i686                   3/10 
 Verifying : crontabs-1.10-33.el6.noarch                   4/10 
 Verifying : sysstat-9.0.4-31.el6.i686                    5/10 
 Verifying : cronie-anacron-1.4.4-16.el6_8.2.i686                  6/10 
 Verifying : cronie-1.4.4-16.el6_8.2.i686                   7/10 
 Verifying : mysql-libs-5.1.73-7.el6.i686                   8/10 
 Verifying : mysql-5.1.73-7.el6.i686                    9/10 
 Verifying : 2:postfix-2.6.6-6.el6_7.1.i686                   10/10 

Removed:
 mysql.i686 0:5.1.73-7.el6     mysql-libs.i686 0:5.1.73-7.el6     mysql-server.i686 0:5.1.73-7.el6     

Dependency Removed:
 cronie.i686 0:1.4.4-16.el6_8.2  cronie-anacron.i686 0:1.4.4-16.el6_8.2 crontabs.noarch 0:1.10-33.el6 perl-DBD-MySQL.i686 0:4.013-3.el6 postfix.i686 2:2.6.6-6.el6_7.1 
 redhat-lsb-core.i686 0:4.0-7.el6.centos sysstat.i686 0:9.0.4-31.el6  

Complete!

這樣就卸載完成了,為了保險(xiǎn)起見我們檢查一下系統(tǒng)中是否還有 MySQL 相關(guān)內(nèi)容沒有刪除干凈

[root@coderknock ~]# yum list installed | grep mysql
[root@coderknock ~]# 

上面的情況是沒有未刪除部分,如果有的話可通過下面的命令刪除:

[root@coderknock ~]# yum remove mysql-libs

下載最新版本的 MySQL

查看系統(tǒng)配置信息選擇對(duì)應(yīng) MySQL 包

[root@coderknock ~]# uname -r 
3.10.104-1.el6.elrepo.i686

在瀏覽器打開 sohu提供的MySQL 鏡像(官網(wǎng)速度太慢)

然后根據(jù)自己系統(tǒng)配置選擇對(duì)應(yīng)的 rpm 包,右鍵復(fù)制文件鏈接,我的選擇如下:

下載并解壓

[root@coderknock ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-1.el6.i686.rpm-bundle.tar
--2017-01-06 22:46:15-- http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-1.el6.i686.rpm-bundle.tar
Resolving mirrors.sohu.com... 119.188.36.70
Connecting to mirrors.sohu.com|119.188.36.70|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 448163840 (427M) [application/octet-stream]
Saving to: “mysql-5.7.17-1.el6.i686.rpm-bundle.tar”

100%[=============================================================================================================================================================>] 448,163,840 9.98M/s in 45s 

2017-01-06 22:47:00 (9.54 MB/s) - “mysql-5.7.17-1.el6.i686.rpm-bundle.tar” saved [448163840/448163840]
[root@coderknock ~]# tar xvf mysql-5.7.17-1.el6.i686.rpm-bundle.tar 
mysql-community-libs-compat-5.7.17-1.el6.i686.rpm
mysql-community-client-5.7.17-1.el6.i686.rpm
mysql-community-embedded-devel-5.7.17-1.el6.i686.rpm
mysql-community-devel-5.7.17-1.el6.i686.rpm
mysql-community-common-5.7.17-1.el6.i686.rpm
mysql-community-test-5.7.17-1.el6.i686.rpm
mysql-community-embedded-5.7.17-1.el6.i686.rpm
mysql-community-libs-5.7.17-1.el6.i686.rpm
mysql-community-server-5.7.17-1.el6.i686.rpm

安裝及配置

安裝 rpm 【有依賴關(guān)系,請(qǐng)按下面的步驟安裝,搜索 [root@coderknock ~]# 可跳過安裝日志直接查看相關(guān)命令】

[root@coderknock ~]# yum localinstall mysql-community-common-5.7.17-1.el6.i686.rpm 
Loaded plugins: security
Setting up Local Package Process
Examining mysql-community-common-5.7.17-1.el6.i686.rpm: mysql-community-common-5.7.17-1.el6.i686
Marking mysql-community-common-5.7.17-1.el6.i686.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-common.i686 0:5.7.17-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================
 Package      Arch    Version     Repository        Size
=======================================================================================================================================================================================================
Installing:
 mysql-community-common    i686    5.7.17-1.el6    /mysql-community-common-5.7.17-1.el6.i686    2.5 M

Transaction Summary
=======================================================================================================================================================================================================
Install 1 Package(s)

Total size: 2.5 M
Installed size: 2.5 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : mysql-community-common-5.7.17-1.el6.i686                  1/1 
 Verifying : mysql-community-common-5.7.17-1.el6.i686                  1/1 

Installed:
 mysql-community-common.i686 0:5.7.17-1.el6                    

Complete!
[root@coderknock ~]# yum localinstall mysql-community-libs-5.7.17-1.el6.i686.rpm 
Loaded plugins: security
Setting up Local Package Process
Examining mysql-community-libs-5.7.17-1.el6.i686.rpm: mysql-community-libs-5.7.17-1.el6.i686
Marking mysql-community-libs-5.7.17-1.el6.i686.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-libs.i686 0:5.7.17-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================
 Package      Arch    Version     Repository        Size
=======================================================================================================================================================================================================
Installing:
 mysql-community-libs    i686    5.7.17-1.el6    /mysql-community-libs-5.7.17-1.el6.i686    7.8 M

Transaction Summary
=======================================================================================================================================================================================================
Install 1 Package(s)

Total size: 7.8 M
Installed size: 7.8 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : mysql-community-libs-5.7.17-1.el6.i686                  1/1 
 Verifying : mysql-community-libs-5.7.17-1.el6.i686                  1/1 

Installed:
 mysql-community-libs.i686 0:5.7.17-1.el6                    

Complete!
[root@coderknock ~]# yum localinstall mysql-community-client-5.7.17-1.el6.i686.rpm 
Loaded plugins: security
Setting up Local Package Process
Examining mysql-community-client-5.7.17-1.el6.i686.rpm: mysql-community-client-5.7.17-1.el6.i686
Marking mysql-community-client-5.7.17-1.el6.i686.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.i686 0:5.7.17-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================
 Package      Arch    Version     Repository        Size
=======================================================================================================================================================================================================
Installing:
 mysql-community-client    i686    5.7.17-1.el6    /mysql-community-client-5.7.17-1.el6.i686    87 M

Transaction Summary
=======================================================================================================================================================================================================
Install 1 Package(s)

Total size: 87 M
Installed size: 87 M
Is this ok [y/N]: ^[[A^Hy
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : mysql-community-client-5.7.17-1.el6.i686                  1/1 
 Verifying : mysql-community-client-5.7.17-1.el6.i686                  1/1 

Installed:
 mysql-community-client.i686 0:5.7.17-1.el6                    

Complete!
[root@coderknock ~]# yum localinstall mysql-community-server-5.7.17-1.el6.i686.rpm 
Loaded plugins: security
Setting up Local Package Process
Examining mysql-community-server-5.7.17-1.el6.i686.rpm: mysql-community-server-5.7.17-1.el6.i686
Marking mysql-community-server-5.7.17-1.el6.i686.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.i686 0:5.7.17-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================
 Package      Arch    Version     Repository        Size
=======================================================================================================================================================================================================
Installing:
 mysql-community-server    i686    5.7.17-1.el6    /mysql-community-server-5.7.17-1.el6.i686    695 M

Transaction Summary
=======================================================================================================================================================================================================
Install 1 Package(s)

Total size: 695 M
Installed size: 695 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : mysql-community-server-5.7.17-1.el6.i686                  1/1 
 Verifying : mysql-community-server-5.7.17-1.el6.i686                  1/1 

Installed:
 mysql-community-server.i686 0:5.7.17-1.el6                    

Complete!

配置

查看版本

[root@coderknock ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.17, for Linux (i686) using EditLine wrapper

啟動(dòng) MySQL

[root@coderknock ~]# service mysqld start
MySQL Daemon failed to start.
Starting mysqld:   [FAILED]

上面的情況說明啟動(dòng)失敗,這是因?yàn)榻?jīng)過上面的步驟,MySQL 最新版已經(jīng)安裝到我們的系統(tǒng)了,但這是還沒有初始化數(shù)據(jù),所以導(dǎo)致無法啟動(dòng)。

初始化數(shù)據(jù)庫

[root@coderknock ~]# mysqld --initialize

如果遇到錯(cuò)誤如下:

2017-01-06T14:53:08.889803Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-01-06T14:53:08.892190Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2017-01-06T14:53:08.892475Z 0 [ERROR] Aborting

可以運(yùn)行以下命令【無需再執(zhí)行 mysqld --initialize】:

[root@coderknock ~]# rm -rf /var/lib/mysql
[root@coderknock ~]# service mysqld start
Initializing MySQL database:  [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld:   [ OK ]

這樣我們就啟動(dòng)了 MySQL 服務(wù)

MySQL 無法登陸的解決辦法

登錄時(shí)我遇到了一些問題:

[root@coderknock ~]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

這是因較新版本的 MySQL 因?yàn)榘踩目紤],會(huì)設(shè)置默認(rèn)密碼

[root@coderknock ~]# grep 'temporary password' /var/log/mysqld.log
2017-01-06T14:53:33.490540Z 1 [Note] A temporary password is generated for root@localhost: Ei(GLix_p6/1

這樣就找到了密碼,如果上面方法不可行可以看看是否有 /root/.mysql_secret 文件

或者通過以下方法直接修改密碼:

[root@coderknock ~]# service mysqld stop
Stopping mysqld:      [ OK ]
[root@coderknock ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking 
[1] 14208
[root@coderknock ~]# 2017-01-06T15:02:18.663496Z mysqld_safe Logging to '/var/log/mysqld.log'.
2017-01-06T15:02:18.666764Z mysqld_safe Logging to '/var/log/mysqld.log'.
2017-01-06T15:02:18.693025Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
^C
[root@coderknock ~]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>update mysql.user set authentication_string=password('你的密碼.') where User='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
mysql> update mysql.user set Host='%' where User='root'
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;

注意SQL在Linux下要注意大小寫,執(zhí)行之后Query OK, 1 row affected, 1 warning (0.00 sec),row 之前是1才代表執(zhí)行成功了。update mysql.user set Host='%' where User='root' 這句是為了別的 IP 的機(jī)器也可以登錄我們的MySQL,可以按需執(zhí)行

重置密碼

無論是獲取到了默認(rèn)密碼還是強(qiáng)行修改了密碼。新版 MySQL 在第一次通過密碼登錄后會(huì)無法執(zhí)行SQL:

mysql> select host from mysql.user where User='root';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

這是因?yàn)?MySQL 為了安全會(huì)要求修改初始密碼。

mysql> ALTER USER 'root'@'%' IDENTIFIED BY '你的密碼';

如果遇到ERROR 1819 (HY000): Your password does not satisfy the current policy requirements說明你的密碼太簡(jiǎn)單,需要設(shè)置復(fù)雜點(diǎn)的密碼,有大小寫字母、有數(shù)字、有標(biāo)點(diǎn)基本上就可以通過。
注意,如果你沒有修改過 root 用戶的Host或者修改為非 % 的字符,需要對(duì)上面的語句進(jìn)行對(duì)應(yīng)的修改,例如: ALTER USER ‘root'@'localhost' IDENTIFIED BY ‘你的密碼'

如果遇到ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement 則需要退出安全模式,正常啟動(dòng)MySQL后登陸再進(jìn)行以上操作:

mysql> quit
[root@coderknock ~]# ps -ef|grep mysql
root 14208 12686 0 23:02 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking
mysql 14381 14208 0 23:02 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-grant-tables --skip-networking --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 15148 12686 0 23:23 pts/0 00:00:00 grep mysql
[root@coderknock ~]# kill -9 114208
-bash: kill: (114208) - No such process
[root@coderknock ~]# kill -9 14208
[1]+ Killed   mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@coderknock ~]# kill -9 1438
[root@coderknock ~]# service mysqld start
[root@coderknock ~]# mysql -u root mysql

精彩專題分享:mysql不同版本安裝教程 mysql5.7各版本安裝教程

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • MySQL 升級(jí)方法指南大全
  • linux下安裝升級(jí)mysql到新版本(5.1-5.7)
  • 實(shí)戰(zhàn)MySQL升級(jí)的最佳方法
  • Mysql升級(jí)到5.7后遇到的group by查詢問題解決
  • Win下Mysql5.6升級(jí)到5.7的方法
  • mysql版本5.5.x升級(jí)到5.6.x步驟分享
  • 升級(jí)到MySQL5.7后開發(fā)不得不注意的一些坑
  • Mysql5升級(jí)到Mysql5.5的方法
  • 圖解MYSQL的安裝和數(shù)據(jù)升級(jí)
  • win2008下mysql8.0.11升級(jí)mysql8.0.17版本詳細(xì)步驟

標(biāo)簽:重慶 貴州 臨沂 內(nèi)蒙古 常德 湖州 成都 天津

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Centos MySQL 5.7安裝、升級(jí)教程》,本文關(guān)鍵詞  Centos,MySQL,5.7,安裝,升級(jí),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Centos MySQL 5.7安裝、升級(jí)教程》相關(guān)的同類信息!
  • 本頁收集關(guān)于Centos MySQL 5.7安裝、升級(jí)教程的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章