CentOS 安装mysql5.5.61

官网下载mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz安装包

下载地址:https://dev.mysql.com/downloads/mysql/5.5.html#downloads

第一种方式,安装到默认目录

1、这里安装到默认目录/usr/local

#解压
tar -zxvf mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz
#重命名
mv mysql-5.5.61-linux-glibc2.12-x86_64 mysql
#移动到默认目录
mv mysql /usr/local

2、 创建mysql免登录用户并授权

#创建用户
useradd -s /sbin/nologin -M mysql
#授权
chown -R mysql:mysql /usr/local/mysql
chmod -R 775 /usr/local/mysql

3、 安装

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

出现下面错误

安装依赖

yum -y install perl

yum -y install libaio

再次执行安装命令

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

 安装成功,记住初始密码

 4、 修改配置脚本

#修改脚本
vim ./support-files/mysql.server
#修改下面内容
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#拷贝脚本
cp ./support-files/mysql.server /etc/init.d/mysqld
#授权
chmod 775 /etc/init.d/mysqld

5、配置修改

vim /etc/my.cnf

修改如下

[client]
port=3306
default-character-set=utf8

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/usr/local/mysql/log/error.log
pid-file=/usr/local/mysql/data/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

6、设置开机启动和环境变量

#将数据库服务添加到开机启动
chkconfig --add mysqld
chkconfig mysqld on

#编辑环境变量
vim /etc/profile
#最后加入下面一句
export PATH=$PATH:/usr/local/mysql/bin
#环境变量生效
source /etc/profile

7、启动

service mysqld start

成功 

第二种方式,安装自定义目录

1、这里安装到/opt

#解压
tar -zxvf mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz
#重命名
mv mysql-5.5.61-linux-glibc2.12-x86_64 mysql
#移动到默认目录
mv mysql /opt

2、 创建mysql免登录用户并授权

#创建用户
useradd -s /sbin/nologin -M mysql
#授权
chown -R mysql:mysql /opt/mysql
chmod -R 775 /opt/mysql

3、 安装

#安装依赖
yum -y install perl

yum -y install libaio
./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data

 安装成功,记住临时密码

 

 4、 修改配置脚本

#修改脚本
vim ./support-files/mysql.server
#修改下面内容
basedir=/opt/mysql-5.5.61
datadir=/opt/mysql-5.5.61/data
#拷贝脚本
cp ./support-files/mysql.server /etc/init.d/mysqld
#授权
chmod 775 /etc/init.d/mysqld

5、配置修改

vim /etc/my.cnf

修改如下

[client]
port=3306
default-character-set=utf8

[mysqld]
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/opt/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/opt/mysql/log/error.log
pid-file=/opt/mysql/data/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

6、设置开机启动和环境变量

#将数据库服务添加到开机启动
chkconfig --add mysqld
chkconfig mysqld on

#编辑环境变量
vim /etc/profile
#最后加入下面一句
export PATH=$PATH:/opt/mysql/bin
#环境变量生效
source /etc/profile

7、启动

service mysqld start

报错,日志文件不存在:

 创建文件,并保存

cd /opt/mysql
mkdir log
vim error.log
:wq!保存文件

 再次启动

service mysqld start

成功

8:用上面临时密码连接数据库

mysql -u root -p -S /opt/mysql/mysql.sock

修改密码:

#修改密码
set password for root@localhost = password('root');
#设置远程连接
grant all privileges on *.* to root@'%' identified by 'root';
#刷新权限
flush privileges;

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值