壹,源码包下载
官方链接
自个上传的csdn资源不带boots的源码包
csdn上5.7.10-boots源码包
注意下载带有boots的源码包
壹-壹:卸载系统自带的boots库
rpm -qa |grep boots-*
yum -y remove boost-*
壹-贰 : 卸载系统自带的mysql
rpm -qa |grep mysql
rpm -qa|grep mariadb
yum -y remove mysql*
yum -y remove mariadb*
壹-叁 安装必要的资源依赖包
yum install cmake make gcc gcc-c++ bison ncurses ncurses-devel -y
壹-肆 添加mysql禁止登录的用户及目录规划
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
mkdir -p /henanzhengzhou/mysql/{mysql,datadir,logdir,tmpdir,tmp}
cd /henanzhengzhou
chown -R mysql.mysql mysql/
mysql 数据库目录划分:
mysql软件目录:/henanzhengzhou/mysql/mysql
mysql数据目录:/henanzhengzhou/mysql/datadir
mysql日志目录:/henanzhengzhou/mysql/logdir
壹-伍 上传软件包到服务器上,解压mysql 并编译安装
mkdir /root/soft
cd /root/soft
tar -zxvf mysql-boost-5.7.10.tar.gz
cd /root/soft/mysql-5.7.10/
mysql-boost-5.7.10.tar.gz
一,编译安装
cmake . -DCMAKE_INSTALL_PREFIX=/henanzhengzhou/mysql/mysql \
-DMYSQL_DATADIR=/henanzhengzhou/mysql/datadir \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/root/soft/mysql-5.7.10/boost \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/henanzhengzhou/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
编译可能的问题
如果编译出现错误,请先删除CMakeCache.txt后,再重新编译:
rm -rf CMakeCache.txt
正常完工的提示
如果出现下面的提示就表示成功生成了编译环境:
– Configuring done
– Generating done
二,make进行编译
make
编译完成后,会出现如下信息: [100%] Built target mysqltest_embedded Scanning
dependencies of target my_safe_process [100%] Building CXX object
mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process [100%] Built target
my_safe_process
三,make install
壹-陆,配置文件以及优化参数
cat /etc/my.cnf
[client]
port=3307
socket=/henanzhengzhou/mysql/tmp/mysql.sock
default-character-set=utf8
[mysqld]
port=3307
user=mysql
socket=/henanzhengzhou/mysql/tmp/mysql.sock
pid-file=/henanzhengzhou/mysql/datadir/mysql.pid
basedir=/henanzhengzhou/mysql/mysql
datadir=/henanzhengzhou/mysql/datadir
tmpdir=/henanzhengzhou/mysql/tmpdir
character-set-server=utf8
log_error=/henanzhengzhou/mysql/logdir/mysql.err
server-id=2
log_bin=/henanzhengzhou/mysql/logdir/binlog
general_log_file=/henanzhengzhou/mysql/logdir/general_log
general_log=1
slow_query_log=ON
long_query_time=2
slow_query_log_file=/henanzhengzhou/mysql/logdir/query_log
log_queries_not_using_indexes=ON
壹-柒 初始化数据库
/henanzhengzhou/mysql/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize \
--user=mysql \
--basedir=/henanzhengzhou/mysql \
--datadir=/henanzhengzhou/mysql/datadir
壹-捌 创建启动项
#有两种启动方式,不过基本原理是一致得,都是通过相同的命令: mysqld_safe
systemctl
/etc/init.d/mysqld
使用systemd 管理mysql 服务
新建一个mysql 服务的unit 文件
–defaults-file 这个参数很重要
一, systemctl 启动
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/henanzhengzhou/mysql/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl daemon-reload # 重新加载systemctl文件
systemctl status mysqld # 查看服务启动状态
二, /etc/init.d/mysqld 启动
cp /henanzhengzhou/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
注意修改启动文件的两个配置文件
vim /etc/init.d/mysqld
basedir=/henanzhengzhou/mysql
datadir=/henanzhengzhou/mysql/datadir
/etc/init.d/mysqld status #查看服务启动状态
/etc/init.d/mysqld start #启动服务
/etc/init.d/mysqld restart #重启服务
/etc/init.d/mysqld stop #停止服务
壹-拾:添加环境变量
vi /root/.bash_profile
PATH=
P
A
T
H
:
PATH:
PATH:HOME/bin:/henanzhengzhou/mysql/mysql/bin
source /root/.bash_profile
mysql -uroot -p
三,修改初始密码
alter user user() identified by “123456”;
flush privileges;
use mysql;
update user set host =’%’ where user =‘root’;
四,忘记root密码:
修改配置文件 my.cnf skip-grant-tables
重启数据库服务: /etc/init.d/mysqld start
update mysql.user set authentication_string=password(‘123456’) where user=‘root’;
flush privileges;