天天看點

1. mysql二進制版本安裝

1.1 下載下傳二進制安裝檔案

位址:https://downloads.mysql.com/archives/community/

上傳到/root

[6.8 localhost ~ 0 32]# cat /etc/redhat-release 
CentOS release 6.8 (Final)
[6.8 localhost ~ 0 33]# ll mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz 
-rw-r--r-- 1 root root 661214270 3月  30 23:32 mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
           

1.2 建立使用者

groupadd mysql
useradd mysql  -g mysql
[6.8 localhost ~ 0 35]# id mysql
uid=27(mysql) gid=27(mysql) 組=27(mysql)
           

1.3 建立目錄

mkdir /home/mysql/{program,conf} -p
mkdir /home/mysql/data/mysqldata1/{mydata,sock,tmpdir,log,innodb_ts,innodb_log,undo,slowlog,binlog,relaylog} -p
           

1.4 解壓縮二進制安裝檔案并設定目錄權限

tar -xvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /home/mysql/program/
[6.8 localhost /home/mysql 0 90]# chown -R mysql.mysql /home/mysql/
[6.8 localhost /home/mysql 0 91]# ll
總用量 12
drwxr-xr-x 2 mysql mysql 4096 3月  29 23:39 conf
drwxr-xr-x 3 mysql mysql 4096 3月  29 23:44 data
drwxr-xr-x 3 mysql mysql 4096 3月  29 23:45 program
           

1.5 軟連結,并設定PATH覆寫原有mysql

[6.8 localhost /usr/local/mysql/bin 0 34]# ln -s /home/mysql/program/mysql-5.7.32-linux-glibc2.12-x86_64/ /usr/local/mysql
[6.8 localhost /usr/local/mysql/bin 0 34]# readlink -f mysql
/home/mysql/program/mysql-5.7.32-linux-glibc2.12-x86_64/bin/mysql
[6.8 localhost /usr/local/mysql/bin 0 36]# which mysql
/usr/bin/mysql
[6.8 localhost /usr/local/mysql/bin 0 37]# export PATH=/usr/local/mysql/bin/:$PATH
[6.8 localhost /usr/local/mysql/bin 0 38]# echo $PATH
/usr/local/mysql/bin/:/root/.pyenv/plugins/pyenv-virtualenv/shims:/root/.pyenv/shims:/root/.pyenv/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
[6.8 localhost /usr/local/mysql/bin 0 40]# which mysql
/usr/local/mysql/bin/mysql
[6.8 localhost /usr/local/mysql/bin 0 43]# mysql -V
mysql  Ver 14.14 Distrib 5.7.32, for linux-glibc2.12 (x86_64) using  EditLine wrapper
[6.8 localhost /usr/local/mysql/bin 0 41]# echo 'export PATH=/usr/local/mysql/bin/:$PATH'>>/etc/profile
           

1.6 增加man 文檔

[6.8 localhost / 1 17]# grep mysql /etc/man.config 
MANPATH	/usr/local/mysql/man
[6.8 localhost / 1 18]# man -aw mysql
/usr/share/man/man1/mysql.1.gz
/usr/local/mysql/man/man1/mysql.1
[6.8 localhost / 1 19]# man -M /usr/local/mysql/man mysql
           

1.7 添加庫檔案,頭檔案

[6.8 localhost / 1 42]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[6.8 localhost / 1 43]# ldconfig -v
[6.8 localhost /usr/include 1 60]# ln -s /usr/local/mysql/include/ /usr/include/mysql57
           

1.8 參數檔案

[6.8 localhost ~ 0 12]# mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 
mv /etc/my.cnf /etc/my.cnfbak48     
[6.8 localhost ~ 0 15]# mkdir -p /usr/local/mysql/etc/
[6.8 localhost /usr/local/mysql 0 27]# chown mysql.mysql /usr/local/mysql/etc/
vim my.cnf

[mysqld]
socket=/home/mysql/data/mysqldata1/sock/mysql.sock
user=mysql
basedir=/usr/local/mysql
datadir=/home/mysql/data/mysqldata1/mydata
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
#default-storage-engine=InnoDB
log_bin=/home/mysql/data/mysqldata1/binlog/mysql-bin
relay-log=/home/mysql/data/mysqldata1/relaylog/mysql-relay-bin
server_id=1
#[mysqld_safe]
tmpdir=/home/mysql/data/mysqldata1/tmpdir
log-error=/home/mysql/data/mysqldata1/log/error.log
pid-file=/home/mysql/data/mysqldata1/sock/mysql.pid
slow_query_log
slow_query_log_file=/home/mysql/data/mysqldata1/slowlog/slow-query.log
#skip_name_resolve=on
innodb_file_per_table=on
innodb_data_home_dir=/home/mysql/data/mysqldata1/innodb_ts
innodb_log_group_home_dir=/home/mysql/data/mysqldata1/innodb_log
innodb_undo_directory=/home/mysql/data/mysqldata1/undo/
log_timestamps=SYSTEM
           

1.9 初始化mysql,啟動

mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --initialize-insecure
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld57
chmod +x  /etc/init.d/mysqld57
service mysqld57 start
           

繼續閱讀