美文网首页
基于CentOS6.9的MariaDB二进制安装

基于CentOS6.9的MariaDB二进制安装

作者: Sainbyno | 来源:发表于2017-08-02 21:28 被阅读0次

    去mariadb官网下载二进制安装包

    进入官网www.mariadb.org选择 Download

    进入官网www.mariadb.org选择 Download 点击 Download

    选择版本

    这里选择5.5.57版本

    *选择需要安装的二进制安装包

    选择基于 x86平台使用与Linux的编译完的二进制包

    谢谢MariaDB的免费软件,开源精神是世界的...

    最后这里是填写相关信息的,这里我们无需填写直接选择下载

    安装环境

    Linux 操作系统 CentOS 6.9 版本

    创建数据库存放路径和权限设置

    创建存放数据库目录 -->创建系统用户账号 -->设置系统用户对/app/data目录的权限
    
    [root@host-b app]#pwd
    /app
    [root@host-b app]#
    [root@host-b app]#mkdir /app/data
    [root@host-b app]#
    [root@host-b app]#rz
    
    [root@host-b app]#getent passwd mysql
    [root@host-b app]#
    [root@host-b app]#ls
    data  mariadb-5.5.57-linux-x86_64.tar.gz
    [root@host-b app]#
    [root@host-b app]#useradd -r -d /app/data -s /sbin/nologin -u 36 mysql
    [root@host-b app]#id mysql
    uid=36(mysql) gid=36(mysql) groups=36(mysql)
    [root@host-b app]#ll
    total 218916
    drwxr-xr-x. 2 root root      4096 Aug  2 12:33 data
    -rw-r--r--. 1 root root 224162771 Aug  2  2017 mariadb-5.5.57-linux-x86_64.tar.gz
    [root@host-b app]#
    [root@host-b app]#chown mysql:mysql /app/data
    [root@host-b app]#ll -d data
    drwxr-xr-x. 2 mysql mysql 4096 Aug  2 12:33 data
    [root@host-b app]#
    
    

    解压缩包

    我们安装的是人家已经编译好了的二进制程序包,所以解压后路径不能随便放,按人家编译好的环境来解压!路径为/usr/local

    特别注意路径要指定
    [root@host-b app]#tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/  <--路径一定要正确
    
    

    修改二进制程序的名字和相关权限

    因为我们安装的是人家已经编译好的二进制程序包,人家编译时规定名字叫mysql,所以我们要修改名字,或者创建软连接

    修改解压后目录的名字 --> 创建软链接

    修改mysql目录下的所有文件的所属组为mysql

    为了有权限执行mysql目录下的程序,修改mysql目录下所有文件的所属组为mysql

    到这之后,我们的二进制程序已经解压完了,虽然二进制程序有啦,但是还不能启动。如果现在就启动会报错的,比如路径错误等,所以接下来我们还需要修改配置文件

    修改配置文件

    1. 我们先打开看一下系统自带的配置文件

    数据库路径与我们指定的/app/data不符合
    2. 利用模板自己创建配置文件
    选择配置文件模板
    切进存放模板的目录选择模板

    创建一个配置文件目录,把模板复制过去改名为 my.cfg

    vim 编辑配给文件,数据库路径是必须配置

    生成对应的mysql数据库并放在 /app/data 目录下

    我们用一个脚本生成数据库即可,脚本在解压缩目录下的scripts目录里 :
    /mysql_install_db

    把 /mysql_install_db 脚本找出来

    执行脚本 /mysql_install_db 生成数据库

    [root@host-b mysql]#pwd
    /usr/local/mysql      <---执行脚本的目录
    [root@host-b mysql]#scripts/mysql_install_db --datadir=/app/data --user=mysql  <--指定路径和用户
    Installing MariaDB/MySQL system tables in '/app/data' ...
    170804  4:14:58 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a fu
    ture release.170804  4:14:58 [Note] ./bin/mysqld (mysqld 5.5.57-MariaDB) starting as process 4955 ...
    OK
    Filling help tables...
    170804  4:14:59 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a fu
    ture release.170804  4:14:59 [Note] ./bin/mysqld (mysqld 5.5.57-MariaDB) starting as process 4963 ...
    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 host-b.6.9 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/data'
    
    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@host-b mysql]#
    [root@host-b mysql]#ll /app/data    <--查看该目录
    total 1084
    -rw-rw----. 1 mysql mysql   16384 Aug  4 04:14 aria_log.00000001
    -rw-rw----. 1 mysql mysql      52 Aug  4 04:14 aria_log_control
    drwx------. 2 mysql root     4096 Aug  4 04:14 mysql               <--mysql数据库
    -rw-rw----. 1 mysql mysql   30346 Aug  4 04:14 mysql-bin.000001
    -rw-rw----. 1 mysql mysql 1038814 Aug  4 04:14 mysql-bin.000002
    -rw-rw----. 1 mysql mysql      38 Aug  4 04:14 mysql-bin.index
    drwx------. 2 mysql mysql    4096 Aug  4 04:14 performance_schema
    drwx------. 2 mysql root     4096 Aug  4 04:14 test
    [root@host-b mysql]#
    [root@host-b mysql]#
    
    

    执行完 /mysql_install_db 脚本后 /app/data 目录下生成的数据库文件

    把服务脚本准备好,设置相关权限启动服务

    (1)把服务脚本 mysql.server 放到 /etc/inint.d/ 目录下,并修改为 mysqld
    (2)设置为开机启动
    (3)创建日志文件 mkdir /var/log/mysql.d 注意路径
    (4)修改日志文件的所属主为 mysql
    (5)service mysqld start 启动服务

    把二进制程序路径添加到$PATH变量里

    测试并设置口令

    目前我们虽然能够登陆数据库但是不安全,因为没有设置安全口令谁都可以登录;这样不安全。

    测试查看端都是否打开:

    没有设置安全口令之前:

    执行安全脚本mysql_secure_installation设置口令:


    执行安全脚本mysql_secure_installation的代码块:
    [root@host-b bin]#mysql_secure_installation 
    /usr/local/mysql/bin/mysql_secure_installation: line 393: find_mysql_client: command not
     found
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none):      <-- 输入当前root密码,这里是回车
    OK, successfully used password, moving on...
    
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    
    Set root password? [Y/n] y      <-- 设置root密码么? < y >
    New password:                   <-- 这里输入密码
    Re-enter new password:          <-- 再输入一次密码
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB 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? [Y/n] y          <-- 是否删除匿名用户? < 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? [Y/n] n   <-- 是否禁止root远程登录?   < n > 
     ... skipping.
    
    By default, MariaDB 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? [Y/n] n    <-- 是否删除测试数据库? < y/n都可以 >
     ... skipping.
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] y              <-- 现在从新加载权限表么? < y >
     ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!
    [root@host-b bin]#
    
    

    设置安全口令之后:


    结语

    到这里就完成整个MariaDB数据库的二进制安装!自己学习用的,如果能够帮到读者是我的荣幸;
    最后还要感谢MariaDB数据库的开发者们免费提供的软件,开源精神是世界的!

    相关文章

      网友评论

          本文标题:基于CentOS6.9的MariaDB二进制安装

          本文链接:https://www.haomeiwen.com/subject/bhbylxtx.html