MySQL5.7 Linux7.4源码安装

1、环境和安装包准备

[root@kkk ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)

mysql-boost-5.7.29.tar.gz安装包可以去官网下载

[root@kkk ~]# ls -l /soft/mysql-boost-5.7.29.tar.gz 
-rw-r--r-- 1 root root 51417554 Feb 19 23:41 /soft/mysql-boost-5.7.29.tar.gz

2、目录规划

#basedir
/app/mysql
#datadir
/app/mysql/data
#logdir
/app/mysql/log

3、创建相关mysql用户组及相关目录

创建mysql用户及组
[root@kkk home]# groupadd mysql
[root@kkk home]# useradd -g mysql -s /bin/nologin mysql

创建mysql basedir datadir logdir
[root@kkk home]# mkdir -p /app/mysql/data
[root@kkk home]# mkdir -p /app/mysql/log

export MYSQL_BASE=/app/mysql
export MYSQL_DATA=/app/mysql/data
export MYSQL_LOG=/app/mysql/log

chown -R mysql:mysql /app/mysql

[root@kkk ~]# grep "mysql" /etc/passwd
mysql:x:1003:1011::/home/mysql:/bin/nologin

4、安装mysql相关包

yum -y install cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
yum -y install openssl-devel*

5、编译安装mysql

tar -xzvf mysql-boost-5.7.29.tar.gz -C /app/mysql

cd /app/mysql/mysql-5.7.29

cmake \
-DBUILD_CONFIG=mysql_release \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/app/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/app/mysql/mysql.sock \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci  \
-DWITH_BOOST=boost \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=OFF

make
make install

创建mysql配置文件

cat /etc/my.cnf

[mysqld]
basedir=/app/mysql
datadir=/app/mysql/data
socket=/app/mysql/mysql.sock
log_error=/app/mysql/log/mysqld.log
server-id=1
explicit_defaults_for_timestamp=true

设置PATH
echo "export PATH=/app/mysql/bin:$PATH" 1>> /etc/profile
source /etc/profile

初始化mysql
/app/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data

6、设置mysql开机启动

[root@kkk system]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@kkk system]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@kkk system]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS! 

[root@kkk system]# chkconfig mysqld on

[root@kkk system]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

创建软连接
ln -s /app/mysql/bin/mysqld /sbin/mysqld

7、配置mysql安全向导

配置安全向导前在/etc/my.cnf中添加低配置密码策略

validate_password_policy=LOW
validate_password_length=4

systemctl start mysqld
[root@kkk ~]# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

8、查看是否安装成功

[root@kkk ~]# systemctl status mysqld
?.mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Thu 2020-02-20 01:02:44 CST; 1min 59s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1421 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mysqld.service
           ?..1526 /bin/sh /app/mysql/bin/mysqld_safe --datadir=/app/mysql/data --pid-file=/app/mysql/data/kk...
           ?..1825 /app/mysql/bin/mysqld --basedir=/app/mysql --datadir=/app/mysql/data --plugin-dir=/app/mys...

Feb 20 01:02:32 kkk systemd[1]: Starting LSB: start and stop MySQL...
Feb 20 01:02:44 kkk mysqld[1421]: Starting MySQL........... SUCCESS!
Feb 20 01:02:44 kkk systemd[1]: Started LSB: start and stop MySQL.
[root@kkk ~]# mysql -hlocalhost -uroot -pg3152647
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> system ls -l /app/mysql/log/mysqld.log
-rw-r----- 1 mysql mysql 51002 Feb 20 01:02 /app/mysql/log/mysqld.log
mysql> system ls -l /app/mysql
total 328
drwxr-xr-x  2 root  root    4096 Feb 20 00:24 bin
drwxr-xr-x  5 mysql mysql   4096 Feb 20 01:02 data
drwxr-xr-x  2 root  root    4096 Feb 20 00:24 docs
drwxr-xr-x  3 root  root    4096 Feb 20 00:24 include
drwxr-xr-x  4 root  root    4096 Feb 20 00:24 lib
-rw-r--r--  1 root  root  276202 Dec 18 20:59 LICENSE
drwxr-xr-x  2 mysql mysql   4096 Feb 20 00:27 log
drwxr-xr-x  4 root  root    4096 Feb 20 00:24 man
drwxr-xr-x 38  7161 31415   4096 Feb 20 00:24 mysql-5.7.29
srwxrwxrwx  1 mysql mysql      0 Feb 20 01:02 mysql.sock
-rw-------  1 mysql mysql      5 Feb 20 01:02 mysql.sock.lock
drwxr-xr-x 10 root  root    4096 Feb 20 00:24 mysql-test
-rw-r--r--  1 root  root     587 Dec 18 20:59 README
-rw-r--r--  1 root  root     587 Dec 18 20:59 README-test
drwxr-xr-x 28 root  root    4096 Feb 20 00:24 share
drwxr-xr-x  2 root  root    4096 Feb 20 00:24 support-files
mysql> system ls -l /app/mysql/data
total 122944
-rw-r----- 1 mysql mysql       56 Feb 20 00:27 auto.cnf
-rw------- 1 mysql mysql     1676 Feb 20 00:27 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 Feb 20 00:27 ca.pem
-rw-r--r-- 1 mysql mysql     1112 Feb 20 00:27 client-cert.pem
-rw------- 1 mysql mysql     1680 Feb 20 00:27 client-key.pem
-rw-r----- 1 mysql mysql      298 Feb 20 00:57 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Feb 20 01:02 ibdata1
-rw-r----- 1 mysql mysql 50331648 Feb 20 01:02 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Feb 20 00:27 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Feb 20 01:02 ibtmp1
-rw-r----- 1 mysql mysql        5 Feb 20 01:02 kkk.pid
drwxr-x--- 2 mysql mysql     4096 Feb 20 00:27 mysql
drwxr-x--- 2 mysql mysql     4096 Feb 20 00:27 performance_schema
-rw------- 1 mysql mysql     1680 Feb 20 00:27 private_key.pem
-rw-r--r-- 1 mysql mysql      452 Feb 20 00:27 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 Feb 20 00:27 server-cert.pem
-rw------- 1 mysql mysql     1676 Feb 20 00:27 server-key.pem
drwxr-x--- 2 mysql mysql    12288 Feb 20 00:27 sys
发布了20 篇原创文章 · 获赞 24 · 访问量 2572

猜你喜欢

转载自blog.csdn.net/u011285708/article/details/104403633
今日推荐