基于二进制程序安装mariadb

  • 环境:教室,默认lftp的ip地址:172.16.0.1
  • 基于二进制程序必须安装在/usr/local目录下,并且解压后的目录必须叫mysql
  • lftp 172.16.0.1获取到Mariadb-5.5.36安装包
    1. get到当地目录
  • 展开程序:
  • [root@localhost yum.repos.d]# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
  •  
  • cd到该目录下
  • [root@localhost mariadb-5.5.36-linux-x86_64]# ll
    total 212
    drwxr-xr-x  2 root root   4096 Aug 12 20:46 bin
    -rw-r--r--  1  500  500  17987 Feb 24 07:50 COPYING
    -rw-r--r--  1  500  500  26545 Feb 24 07:50 COPYING.LESSER
    drwxr-xr-x  3 root root   4096 Aug 12 20:46 data
    drwxr-xr-x  2 root root   4096 Aug 12 20:46 docs
    drwxr-xr-x  3 root root   4096 Aug 12 20:46 include
    -rw-r--r--  1  500  500   8694 Feb 24 07:50 INSTALL-BINARY 安装程序的方法
    drwxr-xr-x  3 root root   4096 Aug 12 20:46 lib
    drwxr-xr-x  4 root root   4096 Aug 12 20:46 man
    drwxr-xr-x 11 root root   4096 Aug 12 20:47 mysql-test
    -rw-r--r--  1  500  500 108813 Feb 24 07:50 README 安装程序的方法  
    drwxr-xr-x  2 root root   4096 Aug 12 20:46 scripts
    drwxr-xr-x 27 root root   4096 Aug 12 20:46 share
    drwxr-xr-x  4 root root   4096 Aug 12 20:46 sql-bench
    drwxr-xr-x  4 root root   4096 Aug 12 20:46 support-files
    [root@localhost mariadb-5.5.36-linux-x86_64]# less INSTALL-BINARY
  • image
  • 上面明确的写着如何安装的方法。
  • 因为安装后数据存放在/usr/local/mariadb-5.5-36…./data目录下,这些数据通常非常非常重要,所以建议放到逻辑卷中,一来可以当数据量大了以后方便扩展,二来可以通过快照进行恢复。所以分个区:
  • image
  • 然后可以在根目录下创建个目录,叫mydata,专门放数据库的数据。
  • image
  • 然后再创建系统用户mysql和创建系统组mysql
  • image
  • 直接在根目录系统下挂载有时候不便,所以在刚才建好的目录下再次创建个目录可以叫/data,如mkdir /mydata/data
  • 因为mysql服务应该使用普通用户登录,所以要改下数据库的目录和目录下文件的属主属组,如:
  • image
  • 再次cd回/usr/local目录下,对已经下载过的mariadb…..那个包的名字进行重命名,因为名称要求使用mysql。
  • image
  • 然后我们cd进/usr/local目录下,先让我们看看都生成了什么文件并修改下目录和文件的权限:
  •  image
  • 其中bin/目录下的S表示服务器端,C表示客户端。
  • 下面我们要改/usr/local/mysql/data目录和文件的权限,因为它们跟数据库的数据有关,需要普通用户开启的进程。
  • image
  • mysql第一次启动前要初始化,但先cd到support_files
  • 查看下列5个文件:
  • image
  • 它们分别应用于不同内存的平台上 ,所以我们要看自己的内存,以便使用: free命令
  • 找到所属于自己内存大小的配置文件复制到新建在/etc/mysql目录中去,并重命名为my.cnf
  • image
  • 编辑my.cnf,然后在空白出填入刚创建的保存数据的mydata处,记得一定要在[mysqld]处
  • datadir=/mydata/data
  • 查看安装脚本
  • [root@localhost scripts]# ll
    total 16
    -rwxr-xr-x 1 root mysql 16168 Feb 24 11:08 mysql_install_db
  •  
  • [root@localhost scripts]#  scripts/mysql_install_db --help
    Usage: ./mysql_install_db [OPTIONS]
      --basedir=path       The path to the MariaDB installation directory.
      --builddir=path      If using --srcdir with out-of-directory builds, you
                           will need to set this to the location of the build
                           directory where built files reside.
      --cross-bootstrap    For internal use.  Used when building the MariaDB system
                           tables on a different host than the target.
      --datadir=path       The path to the MariaDB data directory.
      --defaults-extra-file=name
                           Read this file after the global files are read.
      --defaults-file=name Only read default options from the given file name.
      --force              Causes mysql_install_db to run even if DNS does not
                           work.  In that case, grant table entries that normally
                           use hostnames will use IP addresses.
      --help               Display this help and exit.                    
      --ldata=path         The path to the MariaDB data directory. Same as
                           --datadir.
      --no-defaults        Don't read default options from any option file.
      --defaults-file=path Read only this configuration file.
      --rpm                For internal use.  This option is used by RPM files
                           during the MariaDB installation process.
      --skip-name-resolve  Use IP addresses rather than hostnames when creating
                           grant table entries.  This option can be useful if
                           your DNS does not work.
      --srcdir=path        The path to the MariaDB source directory.  This option
                           uses the compiled binaries and support files within the
                           source tree, useful for if you don't want to install
                           MariaDB yet and just want to create the system tables.
      --user=user_name     The login username to use for running mysqld.  Files
                           and directories created by mysqld will be owned by this
                           user. 
  • 上面两个选项很重要,定义了安装启动时用哪个用户登录并且数据库数据存放的目录在哪里
  • 并且必须回到mysql目录下进行安装操作!因为它依赖bin/目录下的文件。执行如下:
  • [root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
    Installing MariaDB/MySQL system tables in '/mydata/data' ...
    OK
  • image
  •  
  • 但是后续还有收尾工作需要完成,还需要在/etc/rc.d/init.d下添加服务脚本,以便service mysqld start/stop/status/restart…,所以
  • 复制目录下support-files里面的mysql.server的服务脚本,粘贴到/etc/rc.d/init.d/并命名为mysqld,最后再用ll 查看下是否other有执行权限:
  • image
  • 并且可以给它加载到开机启动中去,使用chkconfig –add 服务脚本名称
  • chkconfig –list 查看0-6中那些处于开启的:
  • image
  • 最后我们使用service mysqld start 开启服务
  •  image
  • 但是执行会出问题,显示
  • image
  • 提示我们还要去/etc/profile.d/下编辑一个mysql.sh,里面导出环境变量。
  • 添加export PATH=/usr/local/mysql/bin:$PATH
  • 最后source一下,然后就可以正常启动了!
  • image
  • ---------------------------------------------------------------------------------------------------------------------------------------------------------------
  • image SELECT VERSION();选择版本并返回该函数的状态
  • image SELECT USER();查看用户 && SELECT CURRENT_USER();查看当前用户
  • image 还可以用mysql进行计算!
  • image 对头文件做软连接,当开发其他程序的头文件,
  • image
  • 最后关于导出库文件,由于mariadb都是18、19头文件的库,所以编辑/etc/ld.so.conf.d/mysql.conf
  • 写入/usr/local/mysql/lib
  • 再次ldconfig –v | grep mysql
  • image
  • jobs done;
  • 發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章