1. 程式人生 > 實用技巧 >MySQL安裝(二進位制安裝)

MySQL安裝(二進位制安裝)

二進位制安裝

1)下載或者上傳二進位制包

[root@db01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
#或者進到官網下載好包上傳
[root@db01 ~]# rz mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz

2)安裝依賴

[root@db01 ~]# yum install -y ncurses-devel libaio-devel cmake glibc autoconf

3)解壓安裝包

[root@db01 ~]# tar xf mysql-5.6
.42-linux-glibc2.12-x86_64.tar.gz

4)移動並改名

[root@db01 ~]# mv mysql-5.6.42-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.42

5)做軟連線

[root@db01 ~]# ln -s /usr/local/mysql-5.6.42 /usr/local/mysql

6)建立資料庫使用者

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

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

[root@db01 ~]# cd /usr/local/mysql/support-files/
[root@db01 
/usr/local/mysql/support-files]# cp my-default.cnf /etc/my.cnf cp: overwrite ‘/etc/my.cnf’? y [root@db01 /usr/local/mysql/support-files]# cp mysql.server /etc/init.d/mysqld

8)初始化資料庫

#1.進入初始化檔案目錄
[root@db01 /usr/local/mysql/support-files]# cd ../scripts/
[root@db01 /usr/local/mysql/scripts]# ll
total 36
-rwxr-xr-x 1 7161 31415
34558 Sep 10 2018 mysql_install_db #2.執行初始化 [root@db01 /usr/local/mysql/scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user:指定使用者 --basedir:mysql的安裝目錄 --datadir:mysql的資料目錄 #3.初始化成功的標誌 1)初始化過程有兩個ok 2)資料目錄下有庫檔案 [root@db01 /usr/local/mysql/scripts]# ll /usr/local/mysql/data/ total 110600 -rw-rw---- 1 mysql mysql 12582912 Oct 19 17:09 ibdata1 -rw-rw---- 1 mysql mysql 50331648 Oct 19 17:09 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 Oct 19 17:09 ib_logfile1 drwx------ 2 mysql mysql 4096 Oct 19 17:09 mysql drwx------ 2 mysql mysql 4096 Oct 19 17:09 performance_schema drwxr-xr-x 2 mysql mysql 20 Oct 19 16:58 test

9)啟動資料庫

#二進位制安裝沒有配置system管理
[root@db01 /usr/local/mysql/scripts]# systemctl start mysql
Failed to start mysql.service: Unit not found.

#使用啟動指令碼
[root@db01 /usr/local/mysql/scripts]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/db01.err'.
 SUCCESS!

10)驗證資料庫啟動

#檢視埠
[root@db01 /usr/local/mysql/scripts]# netstat -lntp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      7930/mysqld         

#檢視程序
[root@db01 /usr/local/mysql/scripts]# ps -ef | grep mysql
root       7822      1  0 17:14 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/db01.pid
mysql      7930   7822  0 17:14 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=db01.err --pid-file=/usr/local/mysql/data/db01.pid
root       7961   7441  0 17:15 pts/0    00:00:00 grep --color=auto mysql

#登入資料庫
[root@db01 /usr/local/mysql/scripts]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.42 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>

11)配置system管理資料庫啟動

#1.配置system管理資料庫檔案
[root@db01 ~]# 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=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

#2.重新載入system管理配置
[root@db01 ~]# systemctl daemon-reload

#3.使用system管理啟動資料庫
[root@db01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@db01 ~]# systemctl start mysqld

12)配置環境變數

#1.配置環境變數
[root@db01 ~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH

#2.重新載入環境變數
[root@db01 ~]# source /etc/profile

#3.測試mysql命令
[root@db01 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.42 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>