标签:
本博客为源码安装mysql5.7.23案例全过程
环境ubuntu18.04
安装规划:
配置文件:/etc/my.cnf
数据目录:/r2/mysqldata
安装目录:/usr/local/mysql
1.下载mysql-boost
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.23.tar.gz
2.安装工具
sudo apt-get install cmake -y
apt-get install gcc g++ -y
apt-get install git -y
apt-get install libncurses5 libncurses5-dev -y
sudo apt-get install -y build-essential
sudo apt-get install flex bison -y
sudo apt-get install mpi-default-dev libicu-dev python-dev libbz2-dev -y
3.下载并安装boost
3.1下载boost部署包
wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
3.2解压
tar -zxvf boost_1_59_0.tar.gz
3.3编译
cd /r2/soft/boost_1_59_0 && ./bootstrap.sh
最后部分显示如下证明编译成功
Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... /usr
Generating Boost.Build configuration in project-config.jam...
Bootstrapping is done. To build, run:
./b2
To adjust configuration, edit 'project-config.jam'.
Further information:
Command line help:
./b2 --help
Getting started guide:
http://www.boost.org/more/getting_started/unix-variants.html
Boost.Build documentation:
http://www.boost.org/build/doc/html/index.html
3.4b2
cd /r2/soft/boost_1_59_0 && ./b2 -a -sHAVE_ICU=1 # the parameter means that it support icu or unicode #执行时间稍微长
正常执行最后结果如下:
gcc.compile.c++ bin.v2/libs/wave/build/gcc-7/release/link-static/threading-multi/token_ids.o
gcc.compile.c++ bin.v2/libs/wave/build/gcc-7/release/link-static/threading-multi/wave_config_constant.o
common.mkdir bin.v2/libs/wave/build/gcc-7/release/link-static/threading-multi/cpplexer
common.mkdir bin.v2/libs/wave/build/gcc-7/release/link-static/threading-multi/cpplexer/re2clex
gcc.compile.c++ bin.v2/libs/wave/build/gcc-7/release/link-static/threading-multi/cpplexer/re2clex/aq.o
gcc.compile.c++ bin.v2/libs/wave/build/gcc-7/release/link-static/threading-multi/cpplexer/re2clex/cpp_re.o
gcc.archive bin.v2/libs/wave/build/gcc-7/release/link-static/threading-multi/libboost_wave.a
common.copy stage/lib/libboost_wave.a
...updated 1127 targets...
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/r2/soft/boost_1_59_0
The following directory should be added to linker library paths:
/r2/soft/boost_1_59_0/stage/lib
3.5安装
cd /r2/soft/boost_1_59_0 && sudo ./b2 install #这时就把包给装到/usr/local/include/boost目录下了
最后成功标志如下
common.copy /usr/local/lib/libboost_wave.so.1.59.0
ln-UNIX /usr/local/lib/libboost_wave.so
common.copy /usr/local/lib/libboost_exception.a
common.copy /usr/local/lib/libboost_system.a
common.copy /usr/local/lib/libboost_chrono.a
common.copy /usr/local/lib/libboost_timer.a
common.copy /usr/local/lib/libboost_test_exec_monitor.a
...updated 11816 targets...
4.创建目录
cd /r2 && mkdir mysqldata
cd /usr/local && mkdir mysql
5.预编译msyql
cd /r2/soft/mysql-5.7.23 && sudo cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/r2/mysqldata
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/r2/mysqldata/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DENABLE_DOWNLOADS=1
成功的标志如下:
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -std=gnu++03 -DDBUG_OFF
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_MEMORY_STORAGE_ENGINE
WITH_READLINE
-- Build files have been written to: /r2/soft/mysql-5.7.23
注意:如果出现错误,再次编译的时候需要删除CMakeCache.txt文件
6.编译并安装
6.1编译
cd /r2/soft/mysql-5.7.23 && make -j4
成功的标志如下:
[ 98%] Building CXX object unittest/gunit/keyring/CMakeFiles/merge_keyring_file_tests-t.dirplugin/keyring/file_io.cc.o
[100%] Building CXX object unittest/gunit/keyring/CMakeFiles/merge_keyring_file_tests-t.dirplugin/keyring/buffer.cc.o
[100%] Building CXX object unittest/gunit/keyring/CMakeFiles/merge_keyring_file_tests-t.dir///__/plugin/keyring/hash_to_buffer_serializer.cc.o
[100%] Built target mysqld
Scanning dependencies of target udf_example
[100%] Building CXX object sql/CMakeFiles/udf_example.dir/udf_example.cc.o
[100%] Linking CXX shared module udf_example.so
[100%] Built target udf_example
[100%] Linking CXX executable merge_keyring_file_tests-t
[100%] Built target merge_keyring_file_tests-t
[100%] Linking CXX executable merge_large_tests-t
[100%] Built target merge_large_tests-t
6.2安装
cd /r2/soft/mysql-5.7.23 && make install
7.新建mysql组和用户并授权
groupadd mysql
useradd -g mysql mysql
mkdir /usr/local/mysql/data
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql
chown -R mysql /r2/mysqldata
chgrp -R mysql /r2/mysqldata
8.添加mysql的环境变量
vim /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
让其生效source /etc/profile
9.初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/r2/mysqldata
2018-10-04T09:36:02.519395Z 1 [Note] A temporary password is generated for root@localhost: p&Lta1fdsD,j
这个就是初始化密码:p&Lta1fdsD,j
10.优化便捷化操作
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
update-rc.d mysqld defaults
11.启动mysql
service mysqld start
12.登陆并创建账号
mysql -uroot -p 之后输入密码p&Lta1fdsD,j
set password=password("test123456");
grant insert,update,select,create,index,trigger,alter on . to maef@'%' identified by 'test123456';
grant insert,update,select,create,index,trigger,alter on . to maef@'localhost' identified by 'test123456';
flush privileges;
13.安装客户端
apt install mysql-client-core-5.7 -y
apt install mariadb-client-core-10.1 -y
注意:这时默认的配置什么都没有,位置/etc/mysql/my.cnf
14.编写脚本
启动脚本
启动脚本start.sh
!/bin/bash
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/r2/mysqldata &
停止脚本:stop.sh
!/bin/bash
/usr/local/mysql/bin/mysqladmin -uroot -p shutdown &
标签:
来源: https://www.cnblogs.com/maef/p/9742794.html