1.环境准备
2.cmake简介
从mysql5.5起,mysql源码安装开始使用cmake.cmake一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件,能测试编译器所支持的c++特性,类似unix下的automake。
configure方式和 cmake 方式对比区别:
configure command cmake command
------------------------------------------------------------------------------------
./configure cmake .
./configure --help cmake . -lh or ccmake .
##重新编译时,需要清除旧的对象文件和缓存信息----------------------
make clean rm -f cmakecache.txt
##安装选项 --------------------------------------------------------------------
--prefix=/usr/local/mysql -dcmake_install_prefix=/usr/local/mysql
##最终安装--------------------------------------------------------------------
make make
make install make install
使用configure编译完将生成 config.log 和 config.status 文件。
使用cmake编译完在cmakefiles目录下生成 cmakeerror.log 和 cmakeoutput.log 文件。
3.准备工作
boost 下载地址: http://www.boost.org/users/history ;选择1.59.0版本下载,在编译是填写相应参数,指定boost源码位置即可;
tar xf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/boost
[root@001 mysql-5.7.19]# yum -y install gcc-c++ ncurses-devel cmake
## cmake 的检测过程中,如果出现错误,需要重新 cmake, 删除缓存文件
## rm cmakecache.txt , 然后重新 运行 cmake 。
cmake 参数解析 :--------------------------------------
-dcmake_install_prefix=/usr/local/mysql57 指定安装路径
-dmysql_datadir=/data/mysql 指定数据存放路径
-ddefault_charset=utf8
-ddefault_collation=utf8_general_ci 设置字符校验集
-dmysql_tcp_port=3306
-dmysql_unix_addr=/tmp/mysql.sock 设置套接字生成路径
-dmysql_user=mysql
-dwith_myisam_storage_engine=1 存储引擎的支持
-dwith_innobase_storage_engine=1
-dwith_archive_storage_engine=1
-dwith_blackhole_storage_engine=1
-dwith_memory_storage_engine=1
-ddownload_boost=1
-dwith_boost=/usr/local/boost 指定boost扩展源码路径
##此过程很漫长,请耐心等待,#如果出错重新运行配置,需要删除 cmakecache.txt文件,
使用命令: rm -f cmakecache.txt
## 千万注意磁盘空间的使用率。
5.配置文件
[client]
port=3306
socket=/mysql/mysql.sock ##注意修改所有者:mysql
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
skip-grant-tables ##跳过授权表 可以直接进入数据库修改密码
user=mysql
port=3306
basedir=/usr/local/mysql57 ##注意修改所有者:mysql
datadir=/mysql
tmpdir=/tmp
socket=/mysql/mysql.sock
log-error=/mysql/mysqld.log
pid-file=/mysql/mysqld.pid
6.修改启动客户端方式
## 将编译好的 mysql bin 里面的命令,加入到 $path 变量中,可使用[root@server-150 ~]# mysql进入客户端
7.初始化数据库
[root@http9 mysql]# /usr/local/mysql57/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
# 初始化数据库, 确保 /mysql 目录是mysql 可写的。
命令参数解释:
--defaults-file : 指定mysql配置文件路径 ##这里面有我们刚才配置好的参数
--initialize : 初始化随机密码,注意,初始化的密码是一个过期密码,登录后需要立刻修改密码
--user: 指定运行用户
[root@http9 mysql]# /usr/local/mysql57/support-files/mysql.server start
8.修改root密码
[root@server-150 ~]# mysql ##进入数据库
修改密码的三种方法:
方法一 :
mysql> alter user 'root'@'localhost' identified by '123123'; ##成功后修改新密码。
mysql> flush privileges;
方法二:
set password = password('你的新密码'); ## 新版本的root 密码不再接受 弱密码,需要一定的复杂度。
否则会提示错误:
error 1819 (hy000): your password does not satisfy the current policy requirements
方法三:
update mysql.user set authentication_string=password("123123@qq.com");
flush privileges;
总结:修改密码后即可正常使用mysql,与rpm版相比编译版更加简洁,删除数据时只需要将数据目录/mysql和基本目录、usr/local/mysql57删除即可。
如对本文有疑问, 点击进行留言回复!!
express+mongoose实现对mongodb增删改查操作详解
修复 Mac brew 安装 mongodb 报 Error: No available formula with the name ‘mongodb’ 问题详解
网友评论