Ubuntu 16.04源码编译安装MySQL5.7

CentOS源码编译安装,可以参考《CentOS 6源码编译安装MySQL5.6》这篇文章。

1 软件环境

  • Ubuntu 16.04
  • mysql-5.7.24

2 安装前的准备

## Ubuntu 16.04
$ sudo apt-get install make cmake gcc g++ bison libncurses5-dev build-essential

3 设置MYSQL用户名和组

[root@localhost src]# groupadd mysql
[root@localhost src]# useradd -r -g mysql mysql

4 下载源码并解压

MySQL5.7源码直接下载地址:

https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24.tar.gz

root@ubuntu:/opt/src# tar zxvf mysql-5.6.19.tar.gz
root@ubuntu:/opt/src# cd mysql-5.7.24

5 编译安装MYSQL

root@ubuntu:/opt/src/mysql-5.7.24# cmake . \
 -DCMAKE_INSTALL_PREFIX=/opt/mysql \
 -DMYSQL_DATADIR=/data/mysql \
 -DEXTRA_CHARSETS=all \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci

编译时可能会遇到下面问题:

解决方法:

  1. 下载https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
  2. 编译安装boost,安装方法参照这篇文章
root@ubuntu:/opt/src/mysql-5.7.24# make 
root@ubuntu:/opt/src/mysql-5.7.24# make install

6 设置MySQL目录权限

## 新建MYSQL数据文件目录
root@ubuntu:/opt/src/mysql-5.7.24# mkdir -p /data/mysql
## 修改MySQL目录所属的组和用户
root@ubuntu:/opt/src/mysql-5.7.24# cd /opt/mysql
root@ubuntu:/opt/mysql# chown -R mysql .
root@ubuntu:/opt/mysql# chgrp -R mysql .
## 修改MySQL数据目录所属的组和用户
root@ubuntu:/opt/mysql# chown -R mysql:mysql /data/mysql

6 初始化MYSQL数据库

root@ubuntu:/opt/mysql# bin/mysql_install_db --user=mysql  --datadir=/data/mysql
2018-12-04 19:32:06 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-12-04 19:32:06 [ERROR]   Can't locate the language directory.

注意:

mysql5.7和之前版本不同,很多资料上都是这个命令:./scripts/mysql_install_db --user=mysql,而mysql5.7的    mysql_install_db命令是在bin目录下,并且建议用mysqld --initialize命令。

正确执行:

root@ubuntu:/opt/mysql# bin/mysqld --initialize --user=mysql --datadir=/opt/mysql/data
2018-12-04T11:38:00.611145Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-04T11:38:02.454041Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-04T11:38:02.714693Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-04T11:38:02.788272Z 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: 0f064fd9-f7b9-11e8-9ae3-000c293c34c6.
2018-12-04T11:38:02.798690Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-04T11:38:02.804849Z 1 [Note] A temporary password is generated for root@localhost: RvEkM50ey6:p

注意最后一行,这也是和之前版本不同的地方,它给了root一个初始密码,后面登录的时候要用到这个密码。

7 启动MYSQL

## you can start the MySQL daemon with
root@ubuntu:/opt/mysql# bin/mysqld_safe --user=mysql &

## 启动
root@ubuntu:/opt/mysql# support-files/mysql.server start

## 停止
root@ubuntu:/opt/mysql# support-files/mysql.server stop

## 进入MySQL命令行控制台,输入密码是上一步骤临时为root生成的密码
root@ubuntu:/opt/mysql-5.7.24# 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.24

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>

8 简单使用

## 修改生成的root临时密码
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

## 权限修改
mysql> use mysql;
mysql> desc user;
## 添加用户授权并打开远程连接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'abc'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 
mysql> select Host,User,Password from user where User='abc';
mysql> flush privileges;
mysql> exit

9 遇到的问题

root@ubuntu:/opt/mysql# bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.24

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.

Segmentation fault (core dumped)

解决方法:

修改mysql-5.7.24/cmd-line-utils/libedit/terminal.c源码,把terminal_set函数中的char buf[TC_BUFSIZE];注释,再把附近的area = buf;改为area = NULL;如下所示:

/* terminal_set():
 *      Read in the terminal capabilities from the requested terminal
 */
protected int
terminal_set(EditLine *el, const char *term)
{
        int i;
        /*char buf[TC_BUFSIZE];*/
        char *area;
        const struct termcapstr *t;
        sigset_t oset, nset;
        int lins, cols;

        (void) sigemptyset(&nset);
        (void) sigaddset(&nset, SIGWINCH);
        (void) sigprocmask(SIG_BLOCK, &nset, &oset);

        //area = buf;
        area = NULL;

按照上述步骤重新编译安装MySQL和初始化数据库(建议初始化前删除/opt/mysql/data下的数据文件)。

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值