通过cat /etc/redhat-release
查看系统版本:Red Hat Enterprise Linux Server release 7.2 (Maipo)
一、编译与安装
查看可以安装的cmake
和ncurses
版本: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;