mysql二进制编译安装

  在centos上安装mysql可以直接使用yum install mysql 即可,当然也可以使用二进制格式的程序包,通过简单的配置来使用。
 centos7上是默认已经安装好,可以直接使用,不过版本较低,我们可以去官网上下载最新版的源码包在进行配置。

harbor二进制安装 二进制包怎么安装_maria db

【实验】在centos7上实现二进制安装MariaDB。
1、首先进入mariadb的官网下载源码包

harbor二进制安装 二进制包怎么安装_mysql_02

2、通过secureCRT上传至centos7上
[root@localhost app]# rz
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring mariadb-10.2.8-linux-x86_64.tar.gz...
  100%  445172 KB    10857 KB/sec    00:00:41       0 Errors  

[root@localhost app]# ls
mariadb-10.2.8-linux-x86_64.tar.gz
3、将源码包进行解压缩,注意,这里解压缩要指定特定的目录。
[root@localhost app]# tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/
mariadb-10.2.8-linux-x86_64/lib/plugin/query_cache_info.so
mariadb-10.2.8-linux-x86_64/lib/plugin/debug_key_management.so
mariadb-10.2.8-linux-x86_64/lib/plugin/auth_ed25519.so
mariadb-10.2.8-linux-x86_64/lib/plugin/client_ed25519.so
mariadb-10.2.8-linux-x86_64/lib/plugin/server_audit.so
mariadb-10.2.8-linux-x86_64/lib/plugin/auth_pam.so
mariadb-10.2.8-linux-x86_64/lib/plugin/query_response_time.so
mariadb-10.2.8-linux-x86_64/lib/plugin/libdaemon_example.so
mariadb-10.2.8-linux-x86_64/lib/plugin/daemon_example.ini
.........
4、配置文件
[root@localhost app]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mariadb-10.2.8-linux-x86_64  sbin  share  src
[root@localhost local]# ln -s mariadb-10.2.8-linux-x86_64/ mysql   ------> 创建一个硬链接
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mariadb-10.2.8-linux-x86_64  mysql  sbin  share  src
[root@localhost local]# cd mysql/      ------>进入解压的目录
[root@localhost mysql]# ls
bin                 CREDITS            include         man         README-wsrep  sql-bench
COPYING             data               INSTALL-BINARY  mysql-test  scripts       support-files
COPYING.thirdparty  EXCEPTIONS-CLIENT  lib             README.md   share
[root@localhost support-files]# cp my-huge.cnf /etc/mysql/my.cnf    ------>配置文件的名字是指定的,不能随便修改
cp: cannot create regular file ‘/etc/mysql/my.cnf’: No such file or directory      ------>显示没有该目录,手动创建该目录
[root@localhost support-files]# mkdir /etc/mysql
[root@localhost support-files]# cp my-huge.cnf /etc/mysql/my.cnf
[root@localhost support-files]# vim /etc/mysql/my.cnf    ------> 配置文件
[mysqld]                 ------> 在[mysqld]下加入下面三行
datadir = /app/mysqldb   ------> 这里指定的目录可以随意指定,不过后续操作需要对应上,指定数据库的数据存放文件
innodb_file_per_table = no   ------> 指定数据库中每个表都是单独的文件,方便我们后续修改
skip_name_resolve = no    ------> 跳过名字解析

如果我们直接使用yum安装mysql,在安装后会自动创建mysql用户,因为我们这里是编译二进制程序包,所以需要手动来创建mysql用户

[root@localhost mysql]# useradd -r -d /app/mysqldb -s /sbin/nologin -m mysql
[root@localhost mysql]# id mysql
uid=989(mysql) gid=984(mysql) groups=984(mysql)
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb   
Installing MariaDB/MySQL system tables in '/app/mysqldb' ...
2017-10-14 16:27:55 139772340328256 [Warning] option 'skip_name_resolve': boolean value 'no' wasn't recognized. Set to OFF.
2017-10-14 16:27:55 139772340328256 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
2017-10-14 16:27:58 139772339738368 [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'./bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/app/mysqldb'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
[root@localhost mysql]# ls /app/mysqldb/
aria_log.00000001  ib_buffer_pool  ib_logfile0  mysql             mysql-bin.index  performance_schema
aria_log_control   ibdata1         ib_logfile1  mysql-bin.000001  mysql-bin.state  test
以上系统数据库的文件已经创建成功,接下来我们将服务开启
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ls
binary-configure  my-innodb-heavy-4G.cnf  my-small.cnf         mysql.server  wsrep_notify
magic             my-large.cnf            mysqld_multi.server  policy
my-huge.cnf       my-medium.cnf           mysql-log-rotate     wsrep.cnf
[root@localhost support-files]# cp mysql.server /etc/init.d/
[root@localhost support-files]# 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]'.

service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld')
[root@localhost support-files]# chkconfig --add mysqld            
[root@localhost support-files]# 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
5、启动服务
[root@localhost support-files]# service mysqld start
Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
                                                           [FAILED]

------>  启动服务失败,这是因为我们没有创建数据库的日志文件,手动来创建
[root@localhost support-files]# mkdir /var/log/mariadb
[root@localhost support-files]# ll /var/log/mariadb -d
drwxr-xr-x. 2 root root 6 Oct 14 16:34 /var/log/mariadb
[root@localhost support-files]# chown mysql /var/log/mariadb
[root@localhost support-files]# ll /var/log/mariadb -d      
drwxr-xr-x. 2 mysql root 6 Oct 14 16:34 /var/log/mariadb
[root@localhost support-files]# service mysqld start  
Starting mysqld (via systemctl):                           [  OK  ]
------>  开启服务成功
[root@localhost support-files]# ss -ntl
State      Recv-Q Send-Q       Local Address:Port                      Peer Address:Port              
LISTEN     0      128                      *:111                                  *:*                  
LISTEN     0      128                      *:22                                   *:*                  
LISTEN     0      128              127.0.0.1:631                                  *:*                  
LISTEN     0      100              127.0.0.1:25                                   *:*                  
LISTEN     0      80                      :::3306                                :::*                  
LISTEN     0      128                     :::111                                 :::*                  
LISTEN     0      128                     :::22                                  :::*                  
LISTEN     0      128                    ::1:631                                 :::*                  
LISTEN     0      100                    ::1:25                                  :::*                  

------> 3306端口已经打开
  在centos6编译和centos7上步骤相同,只有一点细微不同,就是日志文件创建不同,注意一下就可以了。