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远程链接

 

 

 

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