Linux(RHEL7)安裝yum及MySQL_5.7

Red Hat的yum在線更新是收費的,未註冊則不能使用,這個是要填序列號激活的,解決辦法是更換爲centos的yum。

  1. 首先查看是否安裝yum

直接在終端輸入yum,有參數提示符,則已經安裝yum,否則則沒有安裝yum

2.安裝yum

2.1先查看當前系統中的yum安裝情況

Rpm -qa | grep yum

2.2刪除原有的yum依賴

RPM -qa | grep yum | xargs rpm -e --nodeps

再通過rpm -qa | grep yum查詢,結果爲空,刪除完全;

 

 

2.3下載新的yum依賴包:

yum-3.4.3-158.el7.centos.noarch.rpm

yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm

yum-rhn-plugin-2.0.1-10.el7.noarch.rpm

 

安裝過程,直接選網易鏡像的yum依賴,會出現兩個依賴error:

Q1.rpm版本過低,升級rpm包解決;

Q2.Python-urlgrabber版本低

下載新版本yum-3.4.3-158.el7.centos.noarch.rpm,會出現一系列依賴error;於是採用如下解決方法:

解決方法:將較低版本的yum-3.4.3-132.el7.centos.0.1.noarch.rpm替換

yum-3.4.3-158.el7.centos.noarch.rpm(3.4.3-158版本是網易鏡像centos7下的默認包,較高,此處通過降低版本規避該問題)

可以正常運行,但需要在國內網站rpm.pbone.net下載;下載過程基本沒速度,後來找到其他人分享的下載文件,可以安裝,且可以正常運行,至此yum安裝完成。(相關文件在以附件形式給出)

3.yum源配置文件修改

Yum源配置文件路徑:/etc/yum.repos.d/,該文件夾下最初應該有示例文件,我可能刪除了,現在新建文件CentOS7.repo(注意文件後綴)

#CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$7 - Base - 163.com

#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$7 - Updates - 163.com

#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

此時,RHEL7的yum包安裝成功,可以試着用yum  -y install tree測試下

4.利用Yum安裝MySQL5.7及相關配置

本次MySQL安裝路徑爲默認路徑

MySQLd和MySQL的區別:

mysqld
SQL後臺程序(即MySQL服務器)。要想使用客戶端程序,該程序必須運行,因爲客戶端通過連接服務器來訪問數據庫。

mysql
交互式輸入SQL語句或從文件以批處理模式執行它們的命令行工具。

4.1查看系統中是否已安裝 MySQL 服務

rpm -qa | grep mysql

yum list installed | grep mysql

這些操作基本相同。

4.2如果已安裝則刪除 MySQL 及其依賴的包

yum -y remove mysql-libs.x86_64

4.3下載mysql57-community-release-el7-8.noarch.rpm 的YUM 源

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

可以查看mysql57-community-release-el7-8.noarch.rpm包中的內容:

Rpm -qpl mysql57-community-release-el7-8.noarch.rpm

4.4安裝 mysql57-community-release-el7-8.noarch.rpm

rpm -ivh mysql57-community-release-el7-8.noarch.rpm

安裝完後,得到如下兩個包,可以在yum的配置文件/etc/yum.repos.d中找到:

mysql-community.repo
mysql-community-source.repo

4.5安裝 MySQL,出現提示的話,一路 Y 到底

yum install mysql-server

期間會安裝好多依賴包,這也是用yum安裝的原因,不用挨個去找依賴。

安裝完畢後(Completely!),運行mysql,然後在  /var/log/mysqld.log 文件中會自動生成一個隨機的密碼,我們需要先取得這個隨機密碼,以用於登錄 MySQL 服務端:

service mysqld start  (啓動MySQL)
/var/log/mysqld.log |grep "password"(查看生成的隨機密碼)

將會返回如下內容,末尾字符串就是密碼,把它複製下來:S6eYlfI0-G4w

A temporary password is generated for root@localhost: hilX0U!9i3_6 

4.6登錄到 MySQL 服務端並更新用戶 root 的密碼:

注意:由於 MySQL5.7 採用了密碼強度驗證插件 validate_password,故此我們需要設置一個有一定強度的密碼;(執行MySQL路徑任意),可以設置新密碼爲Mysql@123

mysql -u root -p
hilX0U!9i3_6

然後更改密碼

SET PASSWORD = PASSWORD('your new password');

ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

flush privileges;

設置用戶root可以在任意 IP 下被訪問:

grant all privileges on *.* to root@"%" identified by "new password";

設置用戶 root 可以在本地被訪問:

grant all privileges on *.* to root@"localhost" identified by "new password";

刷新權限使之生效:

flush privileges;

OK,輸入 exit 後用新密碼再次登錄看看吧!

注意:如果用遠程工具還是連接不上,試試用 iptables -F   命令來清除防火牆中鏈中的規則 

4.7MySQL控制命令:啓動、停止、重啓、查看狀態

下面四條命令不管執行路徑:

service mysqld start

service mysqld stop

service mysqld restart

service mysqld status

下面四條命令可能需要在路徑/bin/systemctl 下執行,沒試!

systemctl start mysqld

service mysqld stop

service mysqld restart

systemctl status mysqld

 

4.8設置 MySQL 的字符集爲 UTF-8:

打開 /etc 目錄下的 my.cnf 文件(此文件是 MySQL 的主配置文件):

vim /etc/my.cnf

在 [mysqld] 前添加如下代碼:

[client]

default-character-set=utf8

在 [mysqld] 後添加如下代碼:

character_set_server=utf8

重啓mysql後再登錄,看看字符集,6個utf8就算OK

show variables like '%character%';

 

4.9查看指定的數據庫中指定數據表的字符集,如查看 mysql 數據庫中 servers 表的字符集:

show table status from mysql like '%servers%';

查看指定數據庫中指定表的全部列的字符集,如查看 mysql 數據庫中 servers 表的全部的列的字符集:

show full columns from servers;

 

4.10忘記密碼時,可用如下方法重置:

service mysqld stop

mysqld_safe --user=root --skip-grant-tables --skip-networking &

mysql -u root

進入MySQL後

use mysql;

update user set password=password("new_password") where user="root";

flush privileges;

 

4.11一些文件的存放目錄

配置文件

vim /etc/my.cnf

存放數據庫文件的目錄

cd /var/lib/mysql

日誌記錄文件

vim /var/log/ mysqld.log

服務啓動腳本

/usr/lib/systemd/system/mysqld.service

socket文件

/var/run/mysqld/mysqld.pid

 

4.12 MySQL 採用的 TCP/IP 協議傳輸數據,默認端口號爲 3306,我們可以通過如下命令查看:

netstat -anp

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章