1. 程式人生 > >centos7.5離線安裝mysql5.5.61.tar.gz

centos7.5離線安裝mysql5.5.61.tar.gz

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

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儲存退出

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的登入方法

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

執行下面的命令是修改的內容立即生效:

[[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]vjqvds mysql]# service mysqld restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL..                                           [  OK  ]
[[email protected] mysql]#