1、卸载旧mysql

[[email protected] soft]# find / -name mysql
[[email protected] soft]# find / -name mysql|xargs rm -rf

2、卸载系统自带的Mariadb

[[email protected] soft]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[[email protected] soft]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

3、删除etc目录下的my.cnf(若有则删,没有则忽略)

[[email protected] soft]# rm /etc/my.cnf

4、官网下载mysql压缩包,MySQL Community Server 5.5.62

5、上传到服务器并解压,修改名称

[[email protected] soft]# tar -zxvf mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz
[[email protected] soft]# mv mysql-5.5.61-linux-glibc2.12-x86_64 mysql

6、执行以下命令来创建mysql用户、用户组

[[email protected] soft]# groupadd mysql
[[email protected] soft]# useradd -g mysql mysql

7、在 etc 下新建配置文件my.cnf

[[email protected] soft]# cd mysql
[[email protected] soft]# cp support-files/my-medium.cnf /etc/my.cnf
[[email protected] soft]# vim /etc/my.cnf

并在该文件中添加一下代码,:wq保存退出

centos7.5离线安装mysql5.5.61.tar.gz

8、添加可执行权限

[[email protected] mysql]# chown -R mysql:mysql ./

9、安装、初始化数据库

[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/home/soft/mysql/ --datadir=/home/soft/mysql/data/

会显示出mysql的登录方法

centos7.5离线安装mysql5.5.61.tar.gz

10、修改当前data目录的拥有者为mysql用户

[[email protected] mysql]# chown -R mysql:mysql data

11、授予my.cnf最大权限

[[email protected] mysql]# chown 777 /etc/my.cnf

12、复制启动脚本到资源目录

[[email protected] mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

13、增加mysqld服务控制脚本执行权限

[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysqld

14、将mysqld服务加入到系统服务,检查mysqld服务是否已经生效

[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

15、将mysql的bin目录加入PATH环境变量,编辑 ~/.bash_profile文件,添加内容:export PATH=$PATH:/home/soft/mysql/bin

[[email protected] mysql]# vim ~/.bash_profile

centos7.5离线安装mysql5.5.61.tar.gz

执行下面的命令是修改的内容立即生效:

[[email protected] mysql]# source ~/.bash_profile

16、启动服务

[[email protected] mysql]# service mysqld start
Starting MySQL.Logging to '/home/soft/mysql/data/instance-q7vjqvds.err'.
..                                                         [  OK  ]
[[email protected] mysql]# 

17、登录mysql,密码为空,直接回车跳过,进入mysql,修改密码,设置生效

[[email protected] mysql]# 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.61-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> update user set password=password('123456') 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)

mysql> 

到目前为止mysql安装成功,reboot测试,mysql服务是否正常启动

[[email protected] mysql]# service mysqld restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL..                                           [  OK  ]
[[email protected] mysql]# 

 

相关文章: