centos7安装mysql5.5.62

时间:2022-06-06 18:12:38

mysql是我们最常用的开源的关系型数据库,mysql不同版本有时候安装的方式也不尽相同,下面梳理一下mysql5.5.62版本的安装

1.下载mysql5.5.62,URL:https://downloads.mysql.com/archives/community/ 我这里下载的是64位版本

centos7安装mysql5.5.62

 

 下载后文件为:mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

 

2. 卸载自带的mariadb和mysql

检查是否安装了mariadb和mysql,有时候默认安装了

rpm -qa | grep mariadb
rpm -qa | grep mysql

如果没有,就可以安装mysql,如果有,需要先卸载(remove后为上面命令查询到的内容,全文件名,我这里没有,没法展示)

yum remove mariadb-xxx

 

3.解压文件,修改目录名方便配置

tar -zxvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz -C /opt/soft/
cd /opt/soft
mv mysql-5.5.62-linux-glibc2.12-x86_64 mysql-5.5.62

 

4.在/usr/local/目录下创建到/opt/soft/mysql-5.5.62的软链接

cd /usr/local
ln -s /opt/soft/mysql-5.5.62 mysql

centos7安装mysql5.5.62

 

5.添加mysql用户,修改mysql目录权限,并用此用户执行应用

useradd -s /bin/false -M mysql
cd /opt/soft
chown -R mysql:mysql mysql-5.5.62

 

6.安装mysql,进入mysql目录执行以下命令

cd /opt/soft/mysql-5.5.62
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

出现以下信息,代表成功

centos7安装mysql5.5.62

 

7.拷贝配置文件,将mysql的配置文件拷贝为/etc/目录下的my.cnf,并修改配置文件

cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

[mysqld] # binlog 配置 log-bin=/usr/local/mysql/logs/mysql-bin.log expire-logs-days=14 max-binlog-size=500M server-id=1 # GENERAL basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/urs/local/mysql/mysql.sock user=mysql default-storage-engine=InnoDB character-set-server=utf8
lower_case_table_names = 1 [mysqld_safe] log-error=/usr/local/mysql/mysql-error.log pid-file=/usr/local/mysql/mysqld.pid [client] socket=/usr/local/mysql/mysql.sock [mysql] default-character-set=utf8 socket=/usr/local/mysql/mysql.sock

 

8.拷贝启动程序,将mysql的启动程序拷贝到/etc/init.d/目录下

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

centos7安装mysql5.5.62

 

 9.安装完,启动mysql服务

service mysqld start

centos7安装mysql5.5.62

 启动成功

 

10.配置环境变量,编辑/etc/profile,方便在任何地方用mysql命令

vim /etc/profile

#mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

别忘记重新编译  /etc/profile

source /etc/profile

 

11.登录mysql,修改密码

首次登录没有密码,提示输入密码时,直接回车就行

mysql -uroot -p

centos7安装mysql5.5.62

 修改mysql root用户密码 为 111111 :

mysql> use mysql;
mysql> update user set password=password(111111) where user=root and host=localhost;
mysql> flush privileges;

centos7安装mysql5.5.62

 至此本机登录密码修改完成,若是想让其他机器访问,需要配置远程访问:

GRANT ALL PRIVILEGES ON *.* TO root@% IDENTIFIED BY 111111 WITH GRANT OPTION;

使用远程工具测试一下:

centos7安装mysql5.5.62

 至此搭建mysql 5.5.62版本就完成了

 

12.一些常用命令 

service mysqld start     #启动
service mysqld stop        #关闭    
service mysqld restart    #重启    
service mysqld status     #查看运行状态