CentOS源码编译安装,可以参考《CentOS 6源码编译安装MySQL5.6》这篇文章。
## Ubuntu 16.04
$ sudo apt-get install make cmake gcc g++ bison libncurses5-dev build-essential
[root@localhost src]# groupadd mysql
[root@localhost src]# useradd -r -g mysql mysql
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
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
编译时可能会遇到下面问题:
解决方法:
root@ubuntu:/opt/src/mysql-5.7.24# make
root@ubuntu:/opt/src/mysql-5.7.24# make install
## 新建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
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一个初始密码,后面登录的时候要用到这个密码。
## 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>
## 修改生成的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
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下的数据文件)。