1. 程式人生 > >linux環境下搭建MySQL

linux環境下搭建MySQL

啟動mysql charset serve spool arm bundle mes SQ sign

linux下搭建mysql的方式很多,網上也詳解了很多種搭建方式,有直接yum的、有rpm的、、總之,“坑”是層出不窮,有相關文件依賴性、權限、GPG keys等等。

本人也在今天搭建了一下、是出“坑”了,所以來記錄下。

--------------------------------------------------------------------------------

本次的搭建方式是使用rpm的方式進行搭建。

相關rpm包下載地址:https://pan.baidu.com/s/1ADAJ0p48_3fiOtijSd9QUQ 密碼:z1zm(版本5.7)


第一步:將該包上傳至服務器,進行解壓:

tar -xvf mysql-5.7.16-1.el6.x86_64.rpm-bundle.tar

解壓之後會出現若幹rpm文件:

  mysql-community-client-5.7.16-1.el6.x86_64.rpm

  mysql-community-common-5.7.16-1.el6.x86_64.rpm

  mysql-community-devel-5.7.16-1.el6.x86_64.rpm

  mysql-community-embedded-5.7.16-1.el6.x86_64.rpm

  mysql-community-embedded-devel-5.7.16-1.el6.x86_64.rpm

  mysql-community-libs-5.7.16-1.el6.x86_64.rpm

  mysql-community-libs-compat-5.7.16-1.el6.x86_64.rpm

  mysql-community-server-5.7.16-1.el6.x86_64.rpm

  mysql-community-test-5.7.16-1.el6.x86_64.rpm

第二步:使用rpm -ivh xxxxx命令進行安裝(切記:順序要保證同步、各個文件安裝之間存在依賴性)

  

  1、rpm -ivh mysql-community-common-5.7.16-1.el6.x86_64.rpm、出現如下內容:

  

warning: mysql-community-common-5.7.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
	file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/danish/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/dutch/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/english/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/estonian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/french/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/german/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/greek/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/italian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/japanese/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/korean/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/polish/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/romanian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/russian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/serbian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/slovak/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/spanish/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/swedish/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64
	file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.16-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-5.el6_6.x86_64

  ok,第一行是有點端倪出來了,不過第一步安裝算是完成。、

  

  2、rpm -ivh mysql-community-libs-*.rpm

  這一步、我就遇到坑了,先看下報錯原因。 

warning: mysql-community-libs-5.7.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.16-1.el6.x86_64

  警告行說的報錯原因很明顯:由於yum安裝了舊版本的GPG keys造成的

  還有文件依賴性的原因。(都是同一個版本因此確定版本不會錯,只能是前者)

  解決方案:命令後邊加上 --force --nodeps 看下成功日誌。

Preparing...                ########################################### [100%]
   1:mysql-community-libs   ########################################### [ 50%]
   2:mysql-community-libs-co########################################### [100%]
You have mail in /var/spool/mail/root

  3、rpm -ivh mysql-community-client-5.7.16-1.el6.x86_64.rpm  

Preparing...                ########################################### [100%]
   1:mysql-community-client ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.16-1.el6.x86_64.rpm 
warning: mysql-community-server-5.7.16-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mysql-community-common(x86-64) = 5.7.16-1.el6 is needed by mysql-community-server-5.7.16-1.el6.x86_64

  4、rpm -ivh mysql-community-server-5.7.16-1.el6.x86_64.rpm(這一步、也發生了第二步的原因,加上 --force --nodeps 即可,具體報錯原因具體對待)  

Preparing...                ########################################### [100%]
   1:mysql-community-server ^[^A######                                      ( 15########################################### [100%]

  ok、到這一步,就完成linux下mysql的安裝了(rpm方式)。

啟動mysql服務:  

  service mysqld start

查詢隨機初始root密碼:  

  cat /var/log/mysqld.log | grep "temporary password"

登錄即可:  

  mysql -uroot -p

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.16

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> 

  環境坑、安裝坑、包坑、各種坑,踩到了才是學到了。

  

  

  

  

  

linux環境下搭建MySQL