MySQL运维---二进制安装
一、MySql安装方法
查看最新文章更新:请点击这里
数据库排名:https://db-engines.com/en/ranking
二、二进制安装Mysql
1、下载mysql-5.6.40二进制文件
wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
2、解压
tar -zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
3、创建安装目录,并把mysql移动至安装目录
mkdir /application mv mysql-5.6.40-linux-glibc2.12-x86_64 /application/mysql-5.6.40
4、创建软连接
ln -s /application/mysql-5.6.40/ /application/mysql
5、进入脚本以及配置文件目录,并拷贝配置文件、启动脚本
cd /application/mysql/support-files/
cp my-default.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysqld
6、进入
cd /application/mysql/scripts/
useradd mysql -s /sbin/nologin -M 创建mysql用户,不允许登录,不指定家目录
./mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data 初始化mysql
报错1:
报错原因:执行初始化报错缺少Perl模块
解决方法:安装Perl模块,再次初始化。
yum install autoconf -y
报错2:
报错原因:环境问题
解决办法:装完依赖,在解压,要是还不行,再装一个依赖
yum install -y gcc-c++ gcc glibc
报错3:
报错原因:执行初始化报错缺少libaio包
解决办法:安装依赖libaio包
yum install -y libaio-devel
安装完成,再次初始化
二、启动mysql
1、先授权
chown -R mysql.mysql /application/mysql*
2、启动mysql
[root@controller mysql]# /etc/init.d/mysqld start
报错:
报错原因:安装目录我们的是/application/,和默认的/usr/local,不一致。
3、修改配置文件里面的安装目录
[root@controller mysql]# sed -i 's#/usr/local#/application#g' /etc/init.d/mysqld /application/mysql/bin/mysqld_safe
修改完成,再次启动
启动成功,它会告诉你mysql错误日志会记录在/application/mysql/data/controller.err里面
三、添加环境变量
1、创建环境变量脚本
[root@controller ~]# vim /etc/profile.d/mysql.sh
export PATH="/application/mysql/bin:$PATH"
2、重新加载一下
source /etc/profile
3、登录mysql
[root@controller ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.40 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>