mysql 安裝
1.安裝方式
1.二進制安裝
2.源碼包安裝
3.rpm包安裝
1.二進制安裝
1)上傳或者下載包
[root@db01 ~]# rz
#或者
[root@web01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
2)安裝依賴
先安裝依耐,在解壓之前安裝,防止包在解壓的時候就去找依耐,而出現安裝報錯的問題。
[root@db01 ~]# yum install -y ncurses-devel libaio-devel autoconf
3)解壓包
[root@db01 ~]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
4)移動目錄
一般用戶安裝的軟件放在/usr/local/
下面
[root@db01 ~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/
主文件夾下的一些目錄
[root@db01 /usr/local/mysql-5.6.46-linux-glibc2.12-x86_64]# ll
total 240
drwxr-xr-x 2 root root 4096 Jul 9 10:33 bin # 存放的二進制文件,比如啟動文件在里面
drwxr-xr-x 3 root root 18 Jul 9 10:34 data
drwxr-xr-x 2 root root 55 Jul 9 10:33 docs
drwxr-xr-x 3 root root 4096 Jul 9 10:34 include
drwxr-xr-x 3 root root 316 Jul 9 10:33 lib
-rw-r--r-- 1 7161 31415 221739 Sep 27 2019 LICENSE
drwxr-xr-x 4 root root 30 Jul 9 10:33 man
drwxr-xr-x 10 root root 291 Jul 9 10:34 mysql-test # 存放默認的數據庫
-rw-r--r-- 1 7161 31415 587 Sep 27 2019 README
drwxr-xr-x 2 root root 30 Jul 9 10:33 scripts
drwxr-xr-x 28 root root 4096 Jul 9 10:34 share
drwxr-xr-x 4 root root 4096 Jul 9 10:34 sql-bench
drwxr-xr-x 2 root root 136 Jul 9 10:34 support-files # 里面有默認的配置文件和啟動腳本
5)做軟連接
方便升級和管理目錄
[root@db01 ~]# ln -s /usr/local/mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql
6)創建mysql用戶
用來管理mysql進程的
[root@db01 ~]# useradd mysql -s /sbin/nologin -M
7)拷貝配置文件和啟動腳本
[root@db01 ~]# cd /usr/local/mysql/support-files/
[root@db01 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld
8)初始化數據庫
[root@db01 ~]# cd /usr/local/mysql/scripts/
[root@db01 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
--user: 指定用戶
--basedir: 指定安裝目錄
--datadir: 指定數據目錄
#初始化成功的標志是兩個ok
9)啟動數據庫
[root@db01 scripts]# /etc/init.d/mysqld start
10)配置環境變量
[root@db01 scripts]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@db01 scripts]# source /etc/profile
11)配置system管理mysql
[root@db01 scripts]# 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
[root@db01 scripts]# systemctl daemon-reload
[root@db01 scripts]# systemctl start mysqld
12)確認啟動
[root@db01 scripts]# ps -ef | grep mysql
mysql 12886 1 2 03:10 ? 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root 12921 10636 0 03:11 pts/1 00:00:00 grep --color=auto mysql
[root@db01 scripts]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 12027/redis-server
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 6180/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7113/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7198/master
tcp6 0 0 :::3306 :::* LISTEN 12886/mysqld
tcp6 0 0 :::111 :::* LISTEN 6180/rpcbind
tcp6 0 0 :::22 :::* LISTEN 7113/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7198/master
# 安裝成功
[root@db01 scripts]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.46 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
遇到的報錯
[root@db01 /usr/local/mysql-5.6.46-linux-glibc2.12-x86_64/scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper
# 解決命令
yum -y install autoconf