mysql编译安装

linux编译安装mysql5.7

一、下载源码包

image

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">mkdir /usr/local/src/mysql-5.7.26-src
cd /usr/local/src/mysql-5.7.26-src
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz </pre>

二、添加mysql用户和组

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 ~]# groupadd mysql
[root@node2 ~]# id myql id: myql: no such user
[root@node2 ~]# useradd -d /home/myql -g mysql -m mysql
[root@node2 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)</pre>

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 ~]# passwd mysql
更改用户 mysql 的密码 。
新的 密码:
重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。</pre>

三、新建相关目录,并赋权限给mysql用户

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 home]# mkdir /home/mysql-5.7.26 [root@node2 home]# mkdir /home/mysql-5.7.26/data
[root@node2 home]# mkdir -p /home/mysql-5.7.26/log[root@node2 home]# mkdir -p /home/mysql-5.7.26/run
[root@node2 home]# mkdir -p /home/mysql-5.7.26/tmp</pre>

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 home]# chown -R mysql:mysql /home/mysql-5.7.26/ [root@node2 home]# ll
总用量 0 drwxr-xr-x 6 mysql mysql 51 5月 3 16:25 mysql-5.7.26 [root@node2 home]# cd mysql-5.7.26/ [root@node2 mysql-5.7.26]# ll
总用量 0 drwxr-xr-x 2 mysql mysql 6 5月 3 16:24 data
drwxr-xr-x 4 mysql mysql 33 5月 3 16:25 log
drwxr-xr-x 2 mysql mysql 6 5月 3 16:25 run [root@node2 mysql-5.7.26]# chmod -R 755 /home/mysql-5.7.26/ [root@node2 mysql-5.7.26]# ll
总用量 0 drwxr-xr-x 2 mysql mysql 6 5月 3 16:24 data
drwxr-xr-x 4 mysql mysql 33 5月 3 16:25 log
drwxr-xr-x 2 mysql mysql 6 5月 3 16:25 run </pre>

[
复制代码

](javascript:void(0); "复制代码")

四、解压源码包

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cd /usr/local/src/mysql-5.7.26-src tar -zxvf mysql-5.7.26.tar.gz </pre>

五、安装相关依赖包

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">yum install cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl automake autoconf make libtool bison-devel libaio-devel</pre>

六、安装boost

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cd /usr/local wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxvf boost_1_59_0.tar.gz</pre>

七、编译安装

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cmake \ -DCMAKE_INSTALL_PREFIX=/home/mysql-5.7.26 \ #安装目录</pre>

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">-DINSTALL_DATADIR=/home/mysql-5.7.26/data \ #数据目录</pre>

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">-DDEFAULT_CHARSET=utf8 \ #默认编码 -DDEFAULT_COLLATION=utf8_general_ci \ #默认校验规则 -DEXTRA_CHARSETS=all \ -DWITH_SSL=yes \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ #激活myisam -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #激活innodb -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ # -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DMYSQL_UNIX_ADDR=/home/mysql-5.7.26/run/mysql.sock \ #sock目录 -DMYSQL_TCP_PORT=3306 \ #端口 -DENABLED_LOCAL_INFILE=1 \ #允许导入数据 -DSYSCONFDIR=/etc \ -DWITH_READLINE=on \ #快捷键功能 -DWITH_BOOST=/usr/local/boost_1_59_0 \ #增强插件</pre>

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">make</pre>

最后出现:

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process
[100%] Built target my_safe_process</pre>

编译成功,再执行

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">make install</pre>

最后出现:

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">-- Installing: /home/mysql-5.7.26/./COPYING-test -- Installing: /home/mysql-5.7.26/./README-test -- Up-to-date: /home/mysql-5.7.26/mysql-test/mtr -- Up-to-date: /home/mysql-5.7.26/mysql-test/mysql-test-run -- Installing: /home/mysql-5.7.26/mysql-test/lib/My/SafeProcess/my_safe_process -- Up-to-date: /home/mysql-5.7.26/mysql-test/lib/My/SafeProcess/my_safe_process -- Installing: /home/mysql-5.7.26/mysql-test/lib/My/SafeProcess/Base.pm -- Installing: /home/mysql-5.7.26/support-files/mysqld_multi.server -- Installing: /home/mysql-5.7.26/support-files/mysql-log-rotate -- Installing: /home/mysql-5.7.26/support-files/magic -- Installing: /home/mysql-5.7.26/share/aclocal/mysql.m4 -- Installing: /home/mysql-5.7.26/support-files/mysql.server</pre>

[
复制代码

](javascript:void(0); "复制代码")

进入/home/mysql-5.7.26/目录

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 mysql-5.7.26]# ll
总用量 64 drwxr-xr-x 2 root root 4096 5月 15 09:08 bin -rw-r--r-- 1 root root 17987 4月 13 21:32 COPYING -rw-r--r-- 1 root root 17987 4月 13 21:32 COPYING-test
drwxr-xr-x 2 mysql mysql 6 5月 3 16:24 data
drwxr-xr-x 2 root root 55 5月 15 09:08 docs
drwxr-xr-x 3 root root 4096 5月 15 09:08 include
drwxr-xr-x 4 root root 192 5月 15 09:08 lib
drwxr-xr-x 4 mysql mysql 33 5月 3 16:25 log
drwxr-xr-x 4 root root 30 5月 15 09:08 man drwxr-xr-x 10 root root 4096 5月 15 09:08 mysql-test -rw-r--r-- 1 root root 2478 4月 13 21:32 README -rw-r--r-- 1 root root 2478 4月 13 21:32 README-test
drwxr-xr-x 2 mysql mysql 6 5月 3 16:25 run
drwxr-xr-x 28 root root 4096 5月 15 09:08 share
drwxr-xr-x 2 root root 90 5月 15 09:08 support-files
drwxr-xr-x 2 mysql mysql 6 5月 3 16:25 tmp</pre>

[
复制代码

](javascript:void(0); "复制代码")

安装成功

八、编写配置文件my.cnf

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">mkdir /etc/mysql
cd /etc/mysql
vim my.cnf
[mysqld]
basedir=/home/mysql-5.7.26 datadir=/home/mysql-5.7.26/data
socket=/home/mysql-5.7.26/mysql.sock
user=mysql
symbolic-links=0 [mysqld_safe]
log-error=/home/mysql-5.7.26/log/mysqld.log
pid-file=/home/mysql-5.7.26/run/mysqld.pid</pre>

[
复制代码

](javascript:void(0); "复制代码")

九、初始化系统数据库

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 bin]# ./mysqld –defaults-file=/etc/mysql/my.cnf --initialize --user=mysql --basedir=/home/mysql-5.7.26/ --datadir=/home/mysql-5.7.26/data/

2019-05-15T06:29:58.880090Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-05-15T06:30:00.176430Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-05-15T06:30:00.525258Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-05-15T06:30:00.673537Z 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: ddbee8c3-76da-11e9-9174-90b11c15be09. 2019-05-15T06:30:00.693221Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-05-15T06:30:01.209547Z 0 [Warning] CA certificate ca.pem is self signed. 2019-05-15T06:30:01.257442Z 1 [Note] A temporary password is generated for root@localhost: O3CaqsqoDy+V</pre>

这里显示了第一次登陆时的临时密码,需要记下来

十、启动

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 bin]# touch /home/mysql-5.7.26/log/mysqld.log
[root@node2 bin]# chown -R mysql:mysql /home/mysql-5.7.26/log/mysqld.log
[root@node2 bin]# ./mysqld_safe --defaults-file=/etc/mysql/my.cnf --user=mysql 2019-05-15T06:33:33.794898Z mysqld_safe Logging to '/home/mysql-5.7.26/log/mysqld.log'. 2019-05-15T06:33:33.826283Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data</pre>

十一、添加MySQL服务

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">cp /home/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld</pre>

十二、启动服务

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 bin]# service mysqld start
Starting MySQL. SUCCESS! </pre>

十三、添加mysql的环境变量

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">vim /etc/profile
最后一行添加
export PATH=/home/mysql-5.7.26/bin:$PATH
source /etc/profile</pre>

十四、连接mysql

先查看mysqld.log日志,查找初始密码,初始密码是在第一次运行初始化数据库时由系统生成的

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 data]# cat /home/mysql-5.7.26/log/mysqld.log |grep password 2019-05-15T03:34:45.137254Z 1 [Note] A temporary password is generated for root@localhost: 1ws;,dEy?kM#</pre>

登录

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 Server version: 5.7.26 Copyright (c) 2000, 2019, 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></pre>

[
复制代码

](javascript:void(0); "复制代码")

登录成功,此时执行任何命令,提示

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.</pre>

需要首先修改密码

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">mysql> set PASSWORD=PASSWORD('xxxxxxxx');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> alter user 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)</pre>

[
复制代码

](javascript:void(0); "复制代码")

退出,重新登录

[
复制代码

](javascript:void(0); "复制代码")

<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@node2 log]# /home/mysql-5.7.26/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 Server version: 5.7.26 Source distribution

Copyright (c) 2000, 2019, 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> show database; +--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec</pre>

[
复制代码

](javascript:void(0); "复制代码")

可以执行命令了

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,616评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,020评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,078评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,040评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,154评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,265评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,298评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,072评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,491评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,795评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,970评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,654评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,272评论 3 318
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,985评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,223评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,815评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,852评论 2 351

推荐阅读更多精彩内容

  • 首先,如果你学MySQL只是玩玩,或者只是自用。那么MySQL编译你就不需要了解了。 因为搭建一个yum仓库,简单...
    华中酒徒阅读 686评论 0 3
  • 1 安装依赖文件 yum -y install make gcc-c++ cmake bison-devel n...
    youngxs阅读 361评论 0 0
  • 安装并配置MySQL数据库 3.2.1安装MySQL数据库 1.MySQL数据库的安装环境准备 如果读者没有物理服...
    SkTj阅读 4,033评论 0 6
  • 今天参加统编教材的培训会,专家解读了教材编写的设计意图和各种先进理念。专家讲的的确很好,PPT做得也很精美。理想是...
    顾鸣芬阅读 191评论 0 0
  • ​ 高中的某个暑假,我在老爸做事的工地上打工,那会还是在咸宁。工友里有个姓乐的老头,大家都喊他老乐,他是个退...
    夏三白阅读 215评论 0 0