CentOS安装MySQL5.5

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: CentOS安装MySQL5.5


一 、安装前准备、安装包下载

1 准备安装

由于CentOS7自带的是 Mariadb, 所以先来删除他吧…

  1. 查找版本
# rpm -qa|grep mariadb

执行命令后会出现类似 MariaDB-server-5.5.49-1.el7.centos.x86_64 之类的鬼…记住名字就行了…

  1. 删除
# rpm -e --nodeps 上面查出来的文件名
  1. 删除配置文件
# rm /etc/my.cnf

到这里就OK了…现在我们开始安装mysql

2 下载安装包

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

二、开始安装

1 将tar安装包上传到CentOS并解压

上传

[root@bogon /]# cd /tmp
[root@bogon tmp]# rz              #然后选择安装包上传到CentOS
[root@bogon tmp]# ll
-rw-r--r--.  1 root root 198993245 11月  6 12:35 mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

解压

[root@bogon tmp]# tar -zxvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
[root@bogon tmp]# ll
drwxr-xr-x. 13 root root       213 11月  6 12:41 mysql-5.5.62-linux-glibc2.12-x86_64
-rw-r--r--.  1 root root 198993245 11月  6 12:35 mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
2 移动到/usr/local目录下并改名
[root@bogon tmp]# mv mysql-5.5.62-linux-glibc2.12-x86_64 /usr/local/
[root@bogon tmp]# cd /usr/local/
[root@bogon local]# ll
总用量 0
drwxr-xr-x.  2 root root   6 5月  11 2019 bin
drwxr-xr-x.  2 root root   6 5月  11 2019 etc
drwxr-xr-x.  2 root root   6 5月  11 2019 games
drwxr-xr-x.  2 root root   6 5月  11 2019 include
drwxr-xr-x.  2 root root   6 5月  11 2019 lib
drwxr-xr-x.  2 root root   6 5月  11 2019 lib64
drwxr-xr-x.  2 root root   6 5月  11 2019 libexec
drwxr-xr-x. 13 root root 213 11月  6 12:41 mysql-5.5.62-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root root   6 5月  11 2019 sbin
drwxr-xr-x.  5 root root  49 8月  23 10:42 share
drwxr-xr-x.  2 root root   6 5月  11 2019 src
[root@bogon local]# mv mysql-5.5.62-linux-glibc2.12-x86_64 mysql-5.5.60
[root@bogon local]# ll
总用量 0
drwxr-xr-x.  2 root root   6 5月  11 2019 bin
drwxr-xr-x.  2 root root   6 5月  11 2019 etc
drwxr-xr-x.  2 root root   6 5月  11 2019 games
drwxr-xr-x.  2 root root   6 5月  11 2019 include
drwxr-xr-x.  2 root root   6 5月  11 2019 lib
drwxr-xr-x.  2 root root   6 5月  11 2019 lib64
drwxr-xr-x.  2 root root   6 5月  11 2019 libexec
drwxr-xr-x. 13 root root 213 11月  6 12:41 mysql-5.5.60
drwxr-xr-x.  2 root root   6 5月  11 2019 sbin
drwxr-xr-x.  5 root root  49 8月  23 10:42 share
drwxr-xr-x.  2 root root   6 5月  11 2019 src
3 增加MySQL配置文件
[root@bogon local]# vi /etc/my.cnf

将一下内容复制到新文件中

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306 
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录, 这里的目录一定要是你解压后并且改了名的目录哟..
basedir=/usr/local/mysql-5.5.60
# 设置mysql数据库的数据的存放目录, 这里的目录一定要是你解压后并且改了名的目录哟..
datadir=/usr/local/mysql-5.5.60/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_name=1
max_allowed_packet=16M
4 再配置并安装

配置命令:

# cd /usr/local/mysql-5.5.60
# groupadd mysql
# useradd -g mysql mysql
# chown -R mysql:mysql ./

安装命令:

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.5.60/ --datadir=/usr/local/mysql-5.5.60/data/

演示:

[root@bogon local]# cd mysql-5.5.60/
[root@bogon mysql-5.5.60]# 
[root@bogon mysql-5.5.60]# groupadd mysql
groupadd:“mysql”组已存在
[root@bogon mysql-5.5.60]# useradd -g mysql mysql
useradd:用户“mysql”已存在
[root@bogon mysql-5.5.60]# chown -R mysql:mysql ./
[root@bogon mysql-5.5.60]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.5.60/ --datadir=/usr/local/mysql-5.5.60/data/
Installing MySQL system tables...
....
....
Please report any problems at http://bugs.mysql.com/
[root@bogon mysql-5.5.60]# chown -R mysql:mysql data
[root@bogon mysql-5.5.60]# chown 777 /etc/my.cnf 
[root@bogon mysql-5.5.60]# ll
总用量 56
drwxr-xr-x.  2 mysql mysql  4096 11月  6 12:41 bin
-rw-r--r--.  1 mysql mysql 17987 8月  29 2018 COPYING
drwxr-xr-x.  5 mysql mysql    57 11月  6 12:48 data
drwxr-xr-x.  2 mysql mysql    55 11月  6 12:41 docs
drwxr-xr-x.  3 mysql mysql  4096 11月  6 12:41 include
-rw-r--r--.  1 mysql mysql   301 8月  29 2018 INSTALL-BINARY
drwxr-xr-x.  3 mysql mysql  4096 11月  6 12:41 lib
drwxr-xr-x.  4 mysql mysql    30 11月  6 12:41 man
drwxr-xr-x. 10 mysql mysql  4096 11月  6 12:41 mysql-test
-rw-r--r--.  1 mysql mysql  2496 8月  29 2018 README
drwxr-xr-x.  2 mysql mysql    30 11月  6 12:41 scripts
drwxr-xr-x. 27 mysql mysql  4096 11月  6 12:41 share
drwxr-xr-x.  4 mysql mysql  4096 11月  6 12:41 sql-bench
drwxr-xr-x.  2 mysql mysql  4096 11月  6 12:41 support-files
[root@bogon mysql-5.5.60]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@bogon mysql-5.5.60]# chmod +x /etc/rc.d/init.d/mysqld
[root@bogon mysql-5.5.60]# chkconfig --add mysqld
[root@bogon mysql-5.5.60]# chkconfig --list mysqld
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 
      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。
mysqld          0:关 1:关 2:开 3:开 4:开 5:开 6:关

三、配置并启动服务

1 配置命令(在MySQL目录下)
# chown -R mysql:mysql data
# chown 777 /etc.my.cnf
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld

chmod 和 chown的区别

chown 修改文件和文件夹的用户和用户组属性 
  (1)要修改文件hh.c的所有者.修改为sakia的这个用户所有 
    chown sakia hh.c      #这样就把hh.c的用户访问权限应用到sakia作为所有者 
  (2)将目录 /tmp/sco 这个目录的所有者和组改为sakia和组net 
    chown -R sakia:net /tmp/sco 
chmod 修改文件和文件夹读写执行属性 
  (1)把hh.c文件修改为可写可读可执行 
    chmod 777 hh.c 
  (2)要修改某目录下所有的文件属性为可写可读可执行 
    chmod 777 *.*    #把文件夹名称与后缀名用*来代替就可以了。 
  (3)同理若是要修改所有htm文件的属性 
    chmod 777 *.htm 
  (4)把目录 /tmp/sco修改为可写可读可执行 
    chmod 777 /tmp/sco 
  (5)要修改某目录下所有的文件夹属性为可写可读可执行 
    chmod 777 *   #把文件夹名称用*来代替就可以了 
    (6)要修改/tmp/sco下所有的文件和文件夹及其子文件夹属性为可写可读可执行 
    chmod -R 777 /tmp/sco 
##
可写 w=4 
可读 r=2 
可执行 x=1 
777就是拥有全权限,根据需要可以自由组合用户和组的
##
2 启动服务命令
[root@bogon mysql-5.5.60]# service mysqld start
3 *报错及解决方法

一旦报错

[root@bogon mysql-5.5.60]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql-5.5.60/data/bogon.err'.
201106 12:50:02 mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/usr/local/mysql-5.5.60/data/bogon.pid).

解决方法

随即执行命令:cat  /usr/local/mysql/data/iZ2ze8hspx8qsmxx7b1i9sZ.err查看错误原因
error内容如下:
[ERROR] Can't start server : Bind on unix socket: Permission denied
[ERROR] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
结合先前写入配置/etc/my.cnf:

由上不难理解——

第一:

mysqld_safe Directory ‘/var/lib/mysql’ for UNIX socket file don’t exists.

“var/lib/mysql”目录不存在,首要先创建:

mkdir /var/lib/mysql

第二:

Mysql客户端和服务器端是通过初始化mysql.sock 文件来进行通信,所以服务器在启动时需要写入该文件,因此该文件所存放的目录必须双方都

具有访问权限。而异常日志中表示:

[ERROR] Can’t start server : Bind on unix socket: Permission denied

所以,MySQL服务不具备目录 /var/lib/mysql 的写入权限,无法生成mysql.sock文件,自然服务启动时无法找到该文件。

给目录 /var/lib/mysql 付予写入权限或者最大权限—chmod 777 /var/lib/mysql

[root@bogon lib]# mkdir mysql
[root@bogon lib]# chmod 777 -R mysql/

最终:

[root@bogon lib]# service mysql start
Starting MySQL... SUCCESS! 
4 配置环境变量

配置PATH

# vi ~/.bash_profile

在文件最后面加入以下内容,并使用:wq保存

export PATH=$PATH:/usr/local/mysql-5.5.60/bin

刷新PATH

# source ~/.bash_profile

四、登录并配置远程登录

1 首次登录MySQL
[root@bogon lib]# mysql -uroot -p
2 *报错及解决方法
[root@bogon lib]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
  • 系统是redhad8,binary方式安装完mysql之后,mysql命令登录不成功,报错:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory。按照百度的方法都不成功,应该和系统版本有关,后来自己想到一个方法:yum install libncurses*,完美解决问题。

解决:

[root@bogon lib]# yum -y install libncurses*
[root@bogon lib]# mysql -uroot -p  
Enter password:               #直接回车登录
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.62 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>
3 修改root密码
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=password('需要设置的密码') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> update user set password=password('12345') 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.00 sec)
4 设置远程登录
mysql> grant all privileges on *.* to 'root'@'%' identified by '12345' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

如果远程无法登录则关闭防火墙

[root@bogon lib]# systemctl stop firewalld.service


相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2天前
|
消息中间件 Linux API
centos7 安装rabbitmq自定义版本及配置
centos7 安装rabbitmq自定义版本及配置
|
1天前
|
弹性计算 关系型数据库 MySQL
centos7 mysql安装及配置
本文详细介绍了在阿里云服务器ECS上通过yum源安装MySQL 8.0.12的过程,包括更新yum源、下载并安装MySQL源、解决安装过程中可能遇到的问题等步骤。此外,还介绍了如何启动MySQL服务、设置开机自启、配置登录密码、添加远程登录用户以及处理远程连接异常等问题。适合初学者参考,帮助快速搭建MySQL环境。
15 8
centos7 mysql安装及配置
|
2天前
|
分布式计算 资源调度 Hadoop
centos7二进制安装Hadoop3
centos7二进制安装Hadoop3
|
5天前
|
缓存 运维 Linux
深入解析:一步步掌握 CentOS 7 安装全流程及运维实战技巧
深入解析:一步步掌握 CentOS 7 安装全流程及运维实战技巧
|
5天前
|
Linux
centos安装与卸载软件
centos安装与卸载软件
14 1
|
3天前
|
Linux Python
Centos7安装Python虚拟环境之virtualenv
Centos7安装Python虚拟环境之virtualenv
|
3天前
|
存储 缓存 Linux
LDAP学习笔记之一:Centos7安装389-DS(RHDS)
LDAP学习笔记之一:Centos7安装389-DS(RHDS)
|
3天前
|
前端开发 小程序 Unix
Centos安装前端开发常用软件
Centos安装前端开发常用软件
|
9天前
|
安全 关系型数据库 MySQL
Linux(CentOS6)安装MySQL5.6
Linux(CentOS 6)系统上安装MySQL 5.6版本的详细步骤,包括准备数据存放目录、创建用户、下载安装包、初始化数据库、配置服务脚本、设置环境变量等操作。
34 1
|
12天前
|
关系型数据库 MySQL Java
centos7安装mysql教程及Navicat平替软件
【8月更文挑战第17天】本教程详述CentOS 7上安装MySQL的过程。首先确保移除任何预装的MySQL组件,然后通过wget获取并安装MySQL的YUM源。可以选择安装特定版本如5.7或8.0。安装MySQL服务器后,启动服务并查找初始密码。登录MySQL后应立即更改密码,并可根据需要设置远程访问权限。此外,还推荐使用免费开源的DBeaver作为数据库管理工具,提供了安装步骤以方便管理和操作MySQL数据库。
下一篇
云函数