1. 程式人生 > 實用技巧 >msyql 二進位制安裝(自定義安裝目錄)

msyql 二進位制安裝(自定義安裝目錄)

2.二進位制安裝(自定義安裝目錄)

1)上傳包

[root@db03 ~]# rz

2)安裝依賴

[root@db03 ~]# yum install -y ncurses-devel libaio-devel cmake glibc autoconf gcc-c++

3)解壓

[root@db03 ~]# tar xf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz

4)建立自定義目錄

[root@db03 ~]# mkdir /service

5)移動並改名

[root@db03 ~]# mv mysql-5.6.42-linux-glibc2.12-x86_64 /service/mysql-5.6.42

6)做軟連線

[root@db03 ~]# ln -s /service/mysql-5.6.42 /service/mysql

7)建立使用者

[root@db03 ~]# useradd mysql -s /sbin/nologin -M

8)拷貝啟動檔案和配置檔案

[root@db03 ~]# cd /service/mysql/support-files/
[root@db03 /service/mysql/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y
[root@db03 /service/mysql/support-files]# cp mysql.server /etc/init.d/mysqld

9)初始化

[root@db03 ~]# cd /service/mysql/scripts/
[root@db03 /service/mysql/scripts]# ./mysql_install_db --user=mysql --basedir=/service/mysql --datadir=/service/mysql/data

10)配置system管理啟動MySQL

[root@db03 ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/service/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

[root@db03 ~]# systemctl daemon-reload

11)啟動資料庫

#1.使用system啟動
[root@db03 ~]# systemctl start mysqld
	#檢視程序啟動失敗,沒有任何報錯

#2.使用mysqld啟動指令碼啟動
[root@db03 ~]# /etc/init.d/mysqld start
/etc/init.d/mysqld: line 244: my_print_defaults: command not found
/etc/init.d/mysqld: line 264: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
	#原因:二進位制的包是原始碼包已經生成編譯安裝完成的,在cmake階段已經指定了所有的目錄都是/usr/local/mysql,所以啟動時所有程式都去找/usr/local/mysql目錄,沒有該目錄,所以啟動失敗
	
#3.解決啟動問題
	1)方法一:做軟連線
	[root@db03 ~]# ln -s /service/mysql /usr/local/mysql
	
	2)方法二:修改啟動檔案
	[root@db03 ~]# vim /etc/init.d/mysqld 
	basedir=/service/mysql
	datadir=/service/mysql/data
	
#4.再次測試啟動
[root@db03 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
#或者
[root@db03 ~]# systemctl start mysqld

12)設定環境變數

[root@db02 ~]# vim /etc/profile.d/mysql.sh
export PATH=/service/mysql/bin:$PATH

[root@db02 ~]# source /etc/profile