ubuntu、deepin、深度系统怎样编译安装MySQL5.7数据库

1、下载boost和MySQL源码包

# 进入tmp目录
cd /tmp
# Boost库是为C++语言标准库提供扩展的一些C++程序库的总称,由Boost社区组织开发、维护
wget http://od.mrtom.club/LINUX/mysql/mysql57/boost_1_59_0.tar.gz
# 下载mysql源码包
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.25.tar.gz

2、安装mysql所需的依赖包

apt-get install cmake 'g++' libncurses5-dev git -y

3、解压boost源码包和mysql源码包,并进入mysql目录

root@wxj-Deepin:/tmp# tar xf boost_1_59_0.tar.gz
root@wxj-Deepin:/tmp# tar xf mysql-5.7.21.tar.gz
root@wxj-Deepin:/tmp# cd mysql-5.7.21/

4、cmake编译

cmake  .  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57/ \
 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
 -DMYSQL_DATADIR=/data/mysql/ \
 -DSYSCONFDIR=/etc \
 -DMYSQL_USER=mysql \
 -DMYSQL_TCP_PORT=3306 \
 -DWITH_XTRADB_STORAGE_ENGINE=1 \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITH_PARTITION_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DWITH_MYISAM_STORAGE_ENGINE=1 \
 -DWITH_READLINE=1 \
 -DENABLED_LOCAL_INFILE=1 \
 -DWITH_EXTRA_CHARSETS=1 \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DEXTRA_CHARSETS=all \
 -DWITH_BIG_TABLES=1 \
 -DWITH_DEBUG=0 \
 -DDOWNLOAD_BOOST=1 \
 -DWITH_BOOST=/tmp/boost_1_59_0

拓展参数详解:

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55      Cmake预编译;
 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock           MYSQL Socket通信文件位置;
 -DMYSQL_DATADIR=/data/mysql                    MYSQL数据存放路径;
 -DSYSCONFDIR=/etc                                     配置文件路径; 
 -DMYSQL_USER=mysql                                 MYSQL运行用户;  
 -DMYSQL_TCP_PORT=3306                             MYSQL监听端口;
 -DWITH_XTRADB_STORAGE_ENGINE=1                 开启xtradb引擎支持;
 -DWITH_INNOBASE_STORAGE_ENGINE=1              开启innodb引擎支持
 -DWITH_PARTITION_STORAGE_ENGINE=1             开启partition引擎支持;
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1             开启blackhole引擎支持;
 -DWITH_MYISAM_STORAGE_ENGINE=1                 开启MyISAM引擎支持;
 -DWITH_READLINE=1                                 启用快捷键功能;    
 -DENABLED_LOCAL_INFILE=1                         允许从本地导入数据;
 -DWITH_EXTRA_CHARSETS=1                         支持额外的字符集;   
 -DDEFAULT_CHARSET=utf8                             默认字符集UTF-8; 
 -DDEFAULT_COLLATION=utf8_general_ci                 检验字符;   
 -DEXTRA_CHARSETS=all                             安装所有扩展字符集;
 -DWITH_BIG_TABLES=1                             将临时表存储在磁盘上;
 -DWITH_DEBUG=0                                    禁止调试模式支持;   
 make                                                编译; 
 make install                                        安装。

没有报错才cmake编译成功

编译并安装

make && make install

没有报错安装成功

创建数据目录并赋予权限

 root@wxj-Deepin:/tmp/mysql-5.7.21# mkdir -p /data/mysql57

 root@wxj-Deepin:/tmp/mysql-5.7.21# useradd -s /sbin/nologin mysql

 root@wxj-Deepin:/tmp/mysql-5.7.21# chown -R mysql. /data/mysql57/

复制service启动文件并赋予执行权限

 root@wxj-Deepin:/tmp/mysql-5.7.21# cp support-files/mysql.server /etc/init.d/mysqld57

 root@wxj-Deepin:/tmp/mysql-5.7.21# chmod a+x /etc/init.d/mysqld57 

配置my.cnf配置文件

 root@wxj-Deepin:/tmp/mysql-5.7.21# vim /etc/my.cnf
 [mysqld]
 basedir=/usr/local/mysql57/
 datadir=/data/mysql57/
 port=3307
 pid-file=/data/mysql57/mysql57.pid
 socket=/tmp/mysql.sock

 [mysqld_safe]
 log-error=/data/mysql57/mysql57.log

初始化mysql

root@wxj-Deepin:~# /usr/local/mysql57/bin/mysqld --initialize --user=mysql --datadir=/data/mysql57 --basedir=/usr/local/mysql57

mysql5.7会生成一个默认密码,默认密码比较复杂,第一次登陆数据库需要采用标注的密码

启动服务

root@wxj-Deepin:~# /etc/init.d/mysqld57 restart

查看服务

登录数据库并修改root密码

root@vultr:/tmp/mysql-5.7.21# /usr/local/mysql57/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> alter user 'root'@'localhost' identified by 'Aa123456';
Query OK, 0 rows affected (0.01 sec)

拓展mysql安装目录介绍

 mysql 主配置目录:/usr/local/mysql57

 mysql 数据目录:/data/mysql57

 mysql 命令目录:/usr/local/mysql57/bin/* 比如:mysql、mysqld等。

 mysql 默认配置文件:/etc/my.cnf

 mysql 启动文件:/usr/local/mysql57/support-files/mysql.server 或者
是/etc/init.d/mysqld

 mysql 日志文件:/data/mysql57/mysql57.log

发表评论

登录... 后才能评论