码迷,mamicode.com
首页 > 数据库 > 详细

【数据库】mysql5.7 源码安装

时间:2018-08-25 14:37:12      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:mkdir   exp   schema   内容   cat   efault   more   flush   private   

说明

/home/chuqq/xxx/mysql/mysql-5.7.23是mysql的源码路径,一下所有的目录都是在这个目录下进行的,如需安装,请根据自身的目录情况进行更改。

获取源码

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.23.tar.gz

指定目录:

tar zxvf mysql-boost-5.7.23.tar.gz

cd mysql-5.7.23

  • mysql软件目录: data/mysql/installdir
  • mysql数据目录:data/mysql/datadir/3306/data
  • mysql日志目录:data/mysql/logdir/3306/{bin_log,general_log,error_log,query_log}
mkdir -p data/mysql/installdir 
mkdir -p data/mysql/datadir/3306/data
mkdir -p data/mysql/logdir/3306/{bin_log,general_log,error_log,query_log}

编译

  • 目录
chuqq@chuqq-hp:~/xxx/mysql/mysql-5.7.23$ pwd
/home/chuqq/xxx/mysql/mysql-5.7.23
  • cmake
cmake . -DCMAKE_INSTALL_PREFIX=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/installdir -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DCOMPILATION_COMMENT=‘MySQL xxx‘ -DWITH_READLINE=ON -DWITH_BOOST=./boost -DSYSCONFDIR=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/datadir/3306/data -DMYSQL_UNIX_ADDR=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/datadir/3306/data/mysql.sock

cmake编译参数说明:https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

  • 出现错误CMake Error: Curses library not found. Please install appropriate package

    sudo apt install libncurses5-dev

    再重新执行上边的cmake指令。

  • 编译安装,耗时1h

    make -j4
    make install

配置

为方便期间,我们在源码目录创建conf文件夹放置config文件。

mkdir conf
cd conf
pwd
/home/chuqq/xxx/mysql/mysql-5.7.23/conf
vi my.cnf

my.cnf中内容如下:

[client]
port=3306
socket=data/mysql/datadir/3306/data/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/datadir/3306/data/mysql.sock
pid-file=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/datadir/3306/data/mysql.pid
basedir=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/installdir
datadir=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/datadir/3306/data
tmpdir=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/tmpdir

log_error=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/logdir/3306/error_log/mysql3.err

server-id = 1
log_bin = /home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/logdir/3306/bin_log/binlog

general_log_file=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/logdir/3306/general_log
general_log      = 1

slow_query_log = ON
long_query_time = 2
slow_query_log_file = /home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/logdir/3306/query_log
log_queries_not_using_indexes = ON

初始化数据库

进入mysql指定的install的文件夹中。

cd /home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/installdir/bin
./mysqld --initialize --user=chuqq --basedir=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/installdir --datadir=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/datadir/3306/data

输出内容:注意最后一行为随机分配的初始密码

2018-08-25T01:25:49.587444Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-25T01:25:50.525154Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-25T01:25:50.799908Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-25T01:25:50.993678Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: cd72821b-a805-11e8-b6a4-f0921cec4839.
2018-08-25T01:25:51.040174Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2018-08-25T01:25:51.040952Z 1 [Note] A temporary password is generated for root@localhost: liFR>7H&F%De

安装ssl,可指定文件生成路径

./mysql_ssl_rsa_setup --datadir=/home/chuqq/xxx/mysql/mysql-5.7.23/data/mysql/datadir/3306/data

输出内容:

Generating a 2048 bit RSA private key
...........................................................+++
..........................................................................................................................+++
writing new private key to ‘ca-key.pem‘
-----
Generating a 2048 bit RSA private key
.........+++
...........................................................................................................+++
writing new private key to ‘server-key.pem‘
-----
Generating a 2048 bit RSA private key
...........................................................................+++
....................................................................+++
writing new private key to ‘client-key.pem‘
-----

启动数据库

./mysqld_safe --defaults-file=/home/chuqq/xxx/mysql/mysql-5.7.23/conf/my.cnf &

登录数据库

./mysql -uroot -p
填入上步骤打印的密钥,即可登录。

修改密码

SET PASSWORD = PASSWORD(‘root‘);
ALTER USER root@localhost PASSWORD EXPIRE NEVER;
flush privileges;

注意,上边设置的root用户只能在本地登录,因为设置了localhost。下边我们创建一个可以远程登录的用户。

创建用户

CREATE USER ‘imax‘@‘%‘ IDENTIFIED BY ‘imax‘;
GRANT ALL ON imax.* TO ‘imax‘@‘%‘;
flush privileges;

【数据库】mysql5.7 源码安装

标签:mkdir   exp   schema   内容   cat   efault   more   flush   private   

原文地址:https://www.cnblogs.com/xxxuwentao/p/9533389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!