在 Red Hat 中源码安装 MySQL-5.6.40

通过cat /etc/redhat-release查看系统版本:Red Hat Enterprise Linux Server release 7.2 (Maipo)

一、编译与安装

查看可以安装的cmakencurses版本:yum list | grep -E 'cmake|ncurses'

准备工作:yum install cmake ncurses-devel

# 进入工作目录
cd /home/zhixing/software
# 解压-配置-编译-安装
tar -xzvf mysql-5.6.40.tar.gz
cd mysql-5.6.40/
mkdir bld
cd bld/
cmake -D CMAKE_INSTALL_PREFIX=/home/zhixing/local/mysql ..
make
make install

二、配置

(1)修改/etc/profile,添加环境变量

export PATH=/home/zhixing/local/mysql/bin:$PATH
export LD_LIBRARY_PATH=/home/zhixing/local/mysql/lib:$LD_LIBRARY_PATH

使生效:source /etc/profile

(2)创建mysql用户和组

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

(3)初始化数据库

cd /home/zhixing/local/mysql
scripts/mysql_install_db --user=mysql --basedir=/home/zhixing/local/mysql --datadir=/home/zhixing/mysql/data
cp my.cnf /home/zhixing/mysql/
mkdir -p /home/zhixing/mysql/tmp
chown -R mysql:mysql /home/zhixing/mysql/tmp/

(4)编辑my.cnf

basedir=/home/zhixing/local/mysql
datadir=/home/zhixing/mysql/data
port=3306
socket=/home/zhixing/mysql/tmp/mysql.sock
plugin_dir=/home/zhixing/local/mysql/lib/plugin
log-error=/home/zhixing/mysql/data/error.log

三、运行与连接

# 运行 mysql server
mysqld_safe --defaults-file=/home/zhixing/mysql/my.cnf --user=mysql &
# 客户端连接(首次需要设置密码)
# mysqladmin -S /home/zhixing/mysql/tmp/mysql.sock -u root password <password>
mysqladmin -S /home/zhixing/mysql/tmp/mysql.sock -u root password mypassword
# 客户端连接
mysql -u root -h 127.0.0.1 -p

四、MySQL 常用操作

# 建库与查看
show databases;
# create database <db_name>;
create database active_node;
# 授权
# grant all privileges on <db_name>.* to '<access_name>'@'%' identified by '<access_password>' with grant option;
grant all privileges on active_node.* to 'zhixing'@'%' identified by 'mypassword' with grant option;
flush privileges;
# 撤权
# revoke all privileges on <db_name>.* from <access_name>@'%';
revoke all privileges on active_node.* from zhixing@'%';
flush privileges;
# 查看用户
use mysql;
desc user;
select host,user,password,plugin from user;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值