Centos7安裝Mysql5.5

一、安裝環境

1、環境描述

當前環境是虛擬機中最小化安裝的Centos7, 防火牆開啓狀態。 安裝Mysql5.5.62僅用於學習。

2、系統版本

[root@localhost MySQL-5.5.62]# uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost MySQL-5.5.62]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
[root@localhost MySQL-5.5.62]# 

 3、防火牆狀態

[root@localhost MySQL-5.5.62]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 二 2020-02-11 13:10:54 CST; 2 days ago
     Docs: man:firewalld(1)
 Main PID: 13362 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─13362 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

2月 11 13:10:54 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
2月 11 13:10:54 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

 

二、Mysql5.5下載

下載地址:https://downloads.mysql.com/archives/community/

建議用迅雷下載:MySQL-5.5.62-1.el7.x86_64.rpm-bundle,這個壓縮包,解壓後發現一堆包,如下:

MySQL-client-5.5.62-1.el7.x86_64             68 M    客戶端組件
MySQL-devel-5.5.62-1.el7.x86_64              21 M    想針對於MySQL編譯安裝PHP等依賴於MySQL的組件包
MySQL-embedded-5.5.62-1.el7.x86_64           331 M   MySQL的嵌入式版本
MySQL-server-5.5.62-1.el7.x86_64             190 M   MySQL主程序
MySQL-shared-5.5.62-1.el7.x86_64             7.8 M   共享庫
MySQL-shared-compat-5.5.62-1.el7.x86_64      11 M    爲了兼容老版本的共享庫

以前下載的時候還有以下兩包:
 MySQL-debuginfo      調試MySQL的組件
 MySQL-test           MySQL的測試組件(在線處理功能)

我們只是安裝學習使用,所以我們只安裝MySQL-server、MySQL-client這兩個。

三、上傳安裝包

把將要安裝的兩個包MySQL-server、MySQL-client解壓到新建文件夾MySQL-5.5.62,

將MySQL-5.5.62這個文件夾上傳到root家目錄,即/root/目錄。

四、卸載衝突的軟件

centos7自帶的數據庫mariadb和Mysal衝突,所以先要檢測:

[root@localhost MySQL-5.5.62]# rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@localhost MySQL-5.5.62]# rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps

檢測到mariadb-libs-5.5.64-1.el7.x86_64,直接卸載。

五、安裝Mysql

1、yum安裝

進入MySQL-5.5.62這個目錄,執行yum -y install * 命令一鍵安裝,yum會自動解決依賴性。

[root@localhost MySQL-5.5.62]# yum -y install *
已加載插件:fastestmirror
正在檢查 MySQL-client-5.5.62-1.el7.x86_64.rpm: MySQL-client-5.5.62-1.el7.x86_64
MySQL-client-5.5.62-1.el7.x86_64.rpm 將被安裝
正在檢查 MySQL-server-5.5.62-1.el7.x86_64.rpm: MySQL-server-5.5.62-1.el7.x86_64
MySQL-server-5.5.62-1.el7.x86_64.rpm 將被安裝
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 MySQL-client.x86_64.0.5.5.62-1.el7 將被 安裝
---> 軟件包 MySQL-server.x86_64.0.5.5.62-1.el7 將被 安裝
--> 正在處理依賴關係 perl(Data::Dumper),它被軟件包 MySQL-server-5.5.62-1.el7.x86_64 需要
Loading mirror speeds from cached hostfile
base                                                                                        | 3.6 kB  00:00:00     
extras                                                                                      | 2.9 kB  00:00:00     
updates                                                                                     | 2.9 kB  00:00:00     
--> 正在檢查事務
---> 軟件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

===================================================================================================================
 Package                   架構            版本                   源                                          大小
===================================================================================================================
正在安裝:
 MySQL-client              x86_64          5.5.62-1.el7           /MySQL-client-5.5.62-1.el7.x86_64           68 M
 MySQL-server              x86_64          5.5.62-1.el7           /MySQL-server-5.5.62-1.el7.x86_64          190 M
爲依賴而安裝:
 perl-Data-Dumper          x86_64          2.145-3.el7            base                                        47 k

事務概要
===================================================================================================================
安裝  2 軟件包 (+1 依賴軟件包)

總計:258 M
總下載量:47 k
安裝大小:258 M
Downloading packages:
perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                     |  47 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 數據庫已被非 yum 程序修改。
** 發現 2 個已存在的 RPM 數據庫問題, 'yum check' 輸出如下:
2:postfix-2.10.1-7.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-7.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
  正在安裝    : perl-Data-Dumper-2.145-3.el7.x86_64                                                            1/3 
  正在安裝    : MySQL-server-5.5.62-1.el7.x86_64                                                               2/3 
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
200213 13:02:12 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
200213 13:02:12 [Note] /usr/sbin/mysqld (mysqld 5.5.62) starting as process 36671 ...
200213 13:02:12 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
200213 13:02:12 [Note] /usr/sbin/mysqld (mysqld 5.5.62) starting as process 36678 ...

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

  正在安裝    : MySQL-client-5.5.62-1.el7.x86_64                                                               3/3 
  驗證中      : perl-Data-Dumper-2.145-3.el7.x86_64                                                            1/3 
  驗證中      : MySQL-client-5.5.62-1.el7.x86_64                                                               2/3 
  驗證中      : MySQL-server-5.5.62-1.el7.x86_64                                                               3/3 

已安裝:
  MySQL-client.x86_64 0:5.5.62-1.el7                       MySQL-server.x86_64 0:5.5.62-1.el7                      

作爲依賴被安裝:
  perl-Data-Dumper.x86_64 0:2.145-3.el7                                                                            

完畢!
[root@localhost MySQL-5.5.62]# 

2、RPM安裝

如果用rpm命令安裝,需要解決依賴性,請先安裝或更新下面三個包:

作爲依賴被安裝:
  perl.x86_64 4:5.16.3-294.el7_6                  perl-Carp.noarch 0:1.26-244.el7                    
  perl-Data-Dumper.x86_64 0:2.145-3.el7           perl-Encode.x86_64 0:2.51-7.el7                    
  perl-Exporter.noarch 0:5.68-3.el7               perl-File-Path.noarch 0:2.09-2.el7                 
  perl-File-Temp.noarch 0:0.23.01-3.el7           perl-Filter.x86_64 0:1.49-3.el7                    
  perl-Getopt-Long.noarch 0:2.40-3.el7            perl-HTTP-Tiny.noarch 0:0.033-3.el7                
  perl-PathTools.x86_64 0:3.40-5.el7              perl-Pod-Escapes.noarch 1:1.04-294.el7_6           
  perl-Pod-Perldoc.noarch 0:3.20-4.el7            perl-Pod-Simple.noarch 1:3.28-4.el7                
  perl-Pod-Usage.noarch 0:1.63-3.el7              perl-Scalar-List-Utils.x86_64 0:1.27-248.el7       
  perl-Socket.x86_64 0:2.010-4.el7                perl-Storable.x86_64 0:2.45-3.el7                  
  perl-Text-ParseWords.noarch 0:3.29-4.el7        perl-Time-HiRes.x86_64 4:1.9725-3.el7              
  perl-Time-Local.noarch 0:1.2300-2.el7           perl-constant.noarch 0:1.27-2.el7                  
  perl-libs.x86_64 4:5.16.3-294.el7_6             perl-macros.x86_64 4:5.16.3-294.el7_6              
  perl-parent.noarch 1:0.225-244.el7              perl-podlators.noarch 0:2.5.1-3.el7                
  perl-threads.x86_64 0:1.87-4.el7                perl-threads-shared.x86_64 0:1.43-6.el7

yum -y install perl.x86_64
yum -y install libaio.x86_64
yum -y install net-tools.x86_64

rpm -ivh MySQL-client.x86_64.0.5.5.62-1.el7
rpm -ivh MySQL-server.x86_64.0.5.5.62-1.el7

六、mysql安全初始化

先啓動mysql服務,然後安全初始化。安全初始化之前需要輸入mysql的密碼。mysql5.5版本默認是沒有密碼的,後續版本是默認有密碼的。多了一步獲取初始密碼的操作。我們在這裏就不囉嗦了。

[root@localhost MySQL-5.5.62]# systemctl start mysql
[root@localhost MySQL-5.5.62]# /usr/bin/mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): <---mysql5.5沒有初始密碼,直接回車
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y  <---是否設定root密碼,當然設置了,輸入Y回車
New password:    <---輸入root密碼,並回車,輸入的過程中不會有任何顯示
Re-enter new password:    <---再次輸入root密碼,並回車,輸入的過程中不會有任何顯示
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y  <---是否刪除匿名用戶,刪除,輸入Y回車
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n  <---是否禁止root用戶遠程登錄
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y  <---是否刪除測試數據庫test,刪除,輸入Y回車
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y  <---刷新權限,輸入Y回車
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

七、配置遠程登陸

如果在上面關閉了root遠程登陸,可以使用下面的方法開啓。

[root@localhost MySQL-5.5.62]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.62-log 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> use mysql
Database changed
mysql> select user,host from user;
+------+-----------------------+
| user | host                  |
+------+-----------------------+
| root | 127.0.0.1             |
| root | ::1                   |
| root | localhost             |
| root | localhost.localdomain |
+------+-----------------------+
4 rows in set (0.00 sec)

mysql> update user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

mysql> exit;
Bye

[root@localhost MySQL-5.5.62]# systemctl restart mysql

配置字符集爲UTF8

拷貝/usr/share/mysql/my-huge.cnf文件到/etc/下並重命名爲:my.cnf

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

編輯 vim /etc/my.cnf 文件配置字符集信息

#在對應位置加入如下內容並保存退出
[client]
default-character-set=utf8
		
[mysqld]
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
		
[mysql]
default-character-set=utf8

八、開啓3306端口

查看防火牆狀態

systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 三 2020-02-12 21:14:55 CST; 2h 37min ago
     Docs: man:firewalld(1)
 Main PID: 717 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─717 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

2月 12 21:13:37 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
2月 12 21:14:55 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost MySQL-5.5.62]# firewall-cmd --version   #查看防火牆版本
0.6.3
[root@localhost MySQL-5.5.62]# firewall-cmd --zone=public --add-port=3306/tcp --permanent  #開啓3306tcp端口
success
[root@localhost MySQL-5.5.62]# firewall-cmd --reload  #刷新,重新載入
success
[root@localhost MySQL-5.5.62]# firewall-cmd --zone=public --query-port=3306/tcp  #檢測端口是否開啓
yes

九、用Navicat遠程鏈接

 

 

 

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