目标
安装二进制免编译MySQL,并设置环境变量、密码
准备
版本 |
IP |
配置 |
主机名 |
centos7.2-1511 |
192.168.200.40 |
2G-2vcpu-40G硬盘 |
server |
[root@server src]# ls
mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz php-5.6.30
nginx-1.17.8 php-5.6.30.tar.gz
nginx-1.17.8.tar.gz
[root@server src]# ll -h mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 root root 385M 7月 15 23:45 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
[root@server src]# pwd
/usr/local/src
过程
# 修改主机名
[root@localhost ~]# hostnamectl set-hostname server
[root@localhost ~]# su
# 准备安装包
[root@server ~]# ll -h mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz -rw-r--r-- 1 root root 385M Sep 11 22:34 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
# 解压
[root@server ~]# tar -zxf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
# 移动到指定目录
[root@server ~]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql
# 创建MySQL启动用户,不可登录
[root@server ~]# useradd -s /sbin/nologin mysql
# 创建存放数据目录
[root@server ~]# mkdir -p /data/mysql
# 更改所属组,所属用户权限
[root@server ~]# chown -R mysql:mysql /data/mysql/
[root@server ~]# ls -la /data/mysql/
total 0
drwxr-xr-x 2 mysql mysql 6 Sep 11 22:37 .
drwxr-xr-x 3 root root 18 Sep 11 22:37 ..
[root@server ~]# cd /usr/local/mysql/
# 安装依赖
[root@server ~]# yum install -y perl-Module-Install
[root@server mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
[root@server mysql]# echo $?
0
[root@lnmp mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@lnmp mysql]# vim /etc/my.cnf
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 29
socket = /tmp/mysql.sock
# 配置启动脚本
[root@lnmp mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@lnmp mysql]# chmod 777 /etc/init.d/mysqld
[root@lnmp mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
[root@lnmp mysql]# chkconfig --add mysqld
[root@lnmp mysql]# chkconfig mysql on
[root@lnmp mysql]# service mysqld start
Starting MySQL. SUCCESS!
[root@lnmp mysql]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1462/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2605/master
tcp6 0 0 :::3306 :::* LISTEN 7891/mysqld
tcp6 0 0 :::22 :::* LISTEN 1462/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2605/master
# 配置环境变量
[root@server mysql]# vim /etc/profile
# 最后一行添加
export PATH=$PATH:/usr/lcoal/mysql/bin
[root@server mysql]# source /etc/profile
[root@server mysql]# mysqladmin -uroot password '000000'
Warning: Using a password on the command line interface can be insecure.
[root@server mysql]# mysql -uroot -p000000
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.47 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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> Ctrl-C -- exit!
Aborted
[root@server mysql]#
到这里二进制免编译MySQL安装配置完成。