超级详细的MySql 在centos下的安装过程

1. 首先卸载系统自带的 mysql

# yum remove mysql 

2.安装 ncurses 和 bison 和 gcc-c++

# yum update && yum -y install ncurses-devel bison gcc-c++ 

3.安装cmake

# wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0.tar.gz
# tar -vxzf cmake-3.14.0.tar.gz -C /usr/local
# cd /usr/local/cmake-3.14.0
# ./configure
# make 
# make install
查看 cmake 版本
# cmake -version

4. 创建mysql组和用户

# groupadd mysql
# useradd -g mysql mysql 

5. 创建数据库目录及分配访问权限

# mkdir -p /opt/app/mysql
# chown -R root:mysql /opt/app/mysql
# mkdir -p /opt/app/mysql/data
# chown -R mysql:mysql /opt/app/mysql/data

6. 编译安装mysql 下载mysql源码

下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz 5.7 linux 通用版

# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
# tar -vxzf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local
# cd /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64
# cmake -DCMAKE_INSTALL_PREFIX=/opt/app/mysql -DMYSQL_DATADIR=/opt/app/mysql/data -DSYSCONFDIR=/etc
参数说明:
-DCMAKE_INSTALL_PREFIX    //安装根目录
-DINSTALL_DATADIR         //数据存储目录
-DSYSCONFDIR              //配置文件(my.cnf)目录
# make 
# make install

7. 配置 mysql

# cd /opt/app/mysql
# cp ./support-files/my-default.cnf /etc/my.cnf 
# vim /etc/my.cnf
在 [mysqld] 段修改
basedir = /opt/app/mysql
datadir = /opt/app/mysql/data
保存退出编辑。:wq(保存退出vim)

8. 初始化数据库

# cd /opt/app/mysql
# ./scripts/mysql_install_db --basedir=/opt/app/mysql --datadir=/opt/app/mysql/data --defaults-file=/etc/my.cnf --user=mysql
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld

9. 设置启动脚本变量

# vim /etc/rc.d/init.d/mysqld
basedir=/opt/app/mysql
datadir=/opt/app/mysql/data
保存退出。 :wq(保存退出vim)

10. 设置变量环境

# echo "PATH=$PATH:/opt/app/mysql/bin" >> /etc/profile (永久生效)
# source /etc/profile 使配置文件立即生效
# export PATH=$PATH:/opt/app/mysql/bin (当前生效)

11. 启动服务

# service mysqld start
/etc/init.d/mysqld: line 46: /u/app/mysql: is a directory
/etc/init.d/mysqld: line 47: /u/app/mysql/data: is a directory
Starting MySQL.                                            [  OK  ]

12. 设置数据库管理员root密码

# mysqladmin -u root password 'xxxxxx'

13.设置root用户授权 可在任意机器登录

#mysql -u root -p 
输入密码  此时密码不可见直接输入即可
grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx' with grant option;
flush privileges;
上一篇:MySQL5.6在线表结构变更(online ddl)总结


下一篇:程序员必备网站