二进制安装(自定义目录)
https://www.cnblogs.com/chenlifan/p/13849099.html
二进制安装
[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
[root@db01 ~]# yum install -y ncurses-devel libaio-devel cmake glibc autoconf
[root@db01 ~]# tar xf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
[root@db01 ~]# mv mysql-5.6.42-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.42
[root@db01 ~]# ln -s /usr/local/mysql-5.6.42 /usr/local/mysql
[root@db01 ~]# useradd mysql -s /sbin/nologin -M
[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
#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
#二进制安装没有配置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!
#查看端口
[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>
#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
#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>