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.gzroot@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
编译时可能会遇到下面问题:
解决方法:
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/mysqlroot@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/mysql2018-12-04 19:32:06 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2018-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/data2018-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=457902018-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 withroot@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 -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.24Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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 -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 7Server version: 5.7.24Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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 intterminal_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下的数据文件)
转载于:https://blog.csdn.net/god_wot/article/details/84797103
标签: #linux
评论列表