1. 程式人生 > >二、Cent OS 7 下MySQL安裝(安裝版)

二、Cent OS 7 下MySQL安裝(安裝版)

  • 環境:Cent OS 7
  • MYSQL版本:      [PS:如需資源,請私信博主]
    • MySQL-client-5.5.60-1.sles11.x86_64.rpm
    • MySQL-server-5.5.60-1.sles11.x86_64.rpm

1、檢視 Cent OS 7 是否自帶 mariadb 及解除安裝步驟
# 1.1 查詢
[[email protected] ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64	# 有返回值即代表安裝,具體版本號可不一樣

# 1.2 解除安裝 mariadb [失敗命令]
[
[email protected]
~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 #回顯如下則命令失敗: error: Failed dependencies: libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64 libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64 # 1.3 強制解除安裝 [成功命令] [
[email protected]
~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64 # 1.4 校驗 mariadb 是否解除安裝成功 [無返回結果即代表成功] [[email protected] ~]# rpm -qa | grep mariadb
  • 為什麼要解除安裝mariadb?
  • 原因:安裝MySQL的時候會和mariadb檔案相沖突導致安裝不成功。

2、新建資料夾並複製MySQL

[[email protected] ~]# mkdir /opt/mysql

# 複製
	MySQL-client-5.5.60-1.sles11.x86_64.rpm
	MySQL-server-5.5.60-1.sles11.x86_64.rpm
到 /opt/mysql 下

3、安裝MySQL服務端和客戶端

# 3.1 安裝 MySQL 服務端 [失敗命令]
[[email protected] mysql]# rpm -ivh MySQL-server-5.5.60-1.sles11.x86_64.rpm	
#回顯如下則命令失敗:
warning: MySQL-server-5.5.60-1.sles11.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	aaa_base is needed by MySQL-server-5.5.60-1.sles11.x86_64
	pwdutils is needed by MySQL-server-5.5.60-1.sles11.x86_64
	usr/bin/perl is needed by MySQL-server-5.5.60-1.sles11.x86_64

# 3.2 強制安裝MySQL
 [[email protected] mysql]# rpm -ivh MySQL-server-5.5.60-1.sles11.x86_64.rpm --force --nodeps

執行結果見下圖:
在這裡插入圖片描述

 [[email protected] mysql]# rpm -ivh MySQL-client-5.5.60-1.sles11.x86_64.rpm --force --nodeps

執行結果見下圖:
在這裡插入圖片描述


4、設定/修改MySQL密碼

# 4.1 設定MySQL密碼
[[email protected] mysql]# /usr/bin/mysql_secure_installation
Enter current password for root (enter for none): [這裡直接按 Enter]
#輸入密碼後回顯如下則命令失敗,按 Ctrl+C 退出:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
# 原因:檢視MySQL啟動狀態,可以看到MySQL服務沒有開啟,所以修改密碼前必須先開啟MySQL服務

# 4.2 開啟MySQL服務
# 4.2.1 檢視MySQL服務狀態
[[email protected] mysql]# service mysql status
#回顯如下:ERROR! MySQL is not running

# 4.2.2 開啟MySQL服務
[[email protected] mysql]# service mysql start
#回顯如下:Starting MySQL.. SUCCESS!

見下圖:
在這裡插入圖片描述

# 4.3 再次修改密碼
# 4.3.1 
[[email protected] mysql]# /usr/bin/mysql_secure_installation
...
Enter current password for root (enter for none):[這裡直接按 Enter]
...
Set root password? [Y/n] [輸入 Y]
New password: [輸入root使用者的登入新密碼]
Re-enter new password: [重複輸入新密碼]
Password updated successfully!
Reloading privilege tables..
 ... Success!

見下圖:
在這裡插入圖片描述

5、測試MySQL安裝是否成功

[[email protected] mysql]# mysql -uroot -p
Enter password:[輸入設定的root使用者密碼]
#回顯如下,則安裝及設定密碼成功:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.60 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>