mysql编译安装

linux编译安装mysql5.7

一、下载源码包

image

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

二、添加mysql用户和组

[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)

[root@node2 ~]# passwd mysql
更改用户 mysql 的密码 。
新的 密码:
重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。

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

[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

[
复制代码

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

[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

[
复制代码

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

四、解压源码包

cd /usr/local/src/mysql-5.7.26-src tar -zxvf mysql-5.7.26.tar.gz 

五、安装相关依赖包

yum install cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl automake autoconf make libtool bison-devel libaio-devel

六、安装boost

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

七、编译安装

[
复制代码

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

cmake \ -DCMAKE_INSTALL_PREFIX=/home/mysql-5.7.26 \ #安装目录

-DINSTALL_DATADIR=/home/mysql-5.7.26/data \ #数据目录

-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 \ #增强插件

[
复制代码

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

make

最后出现:

[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

编译成功,再执行

make install

最后出现:

[
复制代码

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

-- 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

[
复制代码

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

进入/home/mysql-5.7.26/目录

[
复制代码

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

[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

[
复制代码

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

安装成功

八、编写配置文件my.cnf

[
复制代码

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

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

[
复制代码

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

九、初始化系统数据库

[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

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

十、启动

[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

十一、添加MySQL服务

cp /home/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld

十二、启动服务

[root@node2 bin]# service mysqld start
Starting MySQL. SUCCESS!

十三、添加mysql的环境变量

vim /etc/profile
最后一行添加
export PATH=/home/mysql-5.7.26/bin:$PATH
source /etc/profile

十四、连接mysql

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

[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#

登录

[
复制代码

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

[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>

[
复制代码

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

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

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

需要首先修改密码

[
复制代码

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

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)

[
复制代码

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

退出,重新登录

[
复制代码

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

[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

[
复制代码

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

可以执行命令了

你可能感兴趣的:(mysql编译安装)