Centos 6中安装二进制数据库最新版本mariadb-5.5.57

一:实验准备;

1、rpm -qa mariadb*查看是否已经安装有mariadb,为了避免重复,若有的话就先将其删除

2、yum info mariadb在Centos 7里执行,查找官网的,其实也可以直接在网上找,然后进去官网后找到最新版本并下载mariadb-5.5.57-linux-x86_64.tar.gz 

3、将下载好的包"rz"拷进linux虚拟机中(我直接拷到了家目录下)

二:实验步骤;

1、创建mysql用户;

[root@Centos6 ~]# getent passwd mysql   #先查看一下该用户是否存在,若存在就不用动,若不存在就创建[root@Centos6 ~]# useradd -d /var/lib/mysql -r -m -s /sbin/nologin mysql   #Centos 7里我将数据库放在了/app/mysqldb下了,这里就放在/var/log/mysql下吧

2、解压缩;

[root@Centos6 ~]# tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/  #因为是已经编译好的二进制文件,目录是已经被制定好的,必须放在/usr/local,故加上-C解压缩到指定目录[root@Centos6 ~]# cd /usr/local/                                             #进入到该目录下[root@Centos6 /usr/local]# lsbin  games    lib    libexec                      shareetc  include  lib64  mariadb-5.5.57-linux-x86_64  sbin   src[root@Centos6 /usr/local]# ln -s mariadb-5.5.57-linux-x86_64/ mysql          #因为名字必须是mysql,所以将其创建软链接[root@Centos6 /usr/local]# cd mysql/                                         #然后进到mysql目录下

3、创建my.cnf配置文件

[root@Centos6 /usr/local/mysql]# mkdir /etc/mysql/                          #编译时默认配置文件放在/etc/mysql下,所以创建一个mysql的目录[root@Centos6 /usr/local/mysql]# ls support-files/                           #二进制文件里已经定义好的配置文件放在/usr/local/mysql/support-files/下binary-configure        my-large.cnf         mysql-log-rotatemagic                   my-medium.cnf        mysql.servermy-huge.cnf             my-small.cnf         SELinuxmy-innodb-heavy-4G.cnf  mysqld_multi.server[root@Centos6 /usr/local/mysql]# cp support-files/my-huge.cnf  /etc/mysql/my.cnf  #将二进制文件里的配置文件(里面有好几个,可以选择其中一个)复制到/etc/mysql/下,并改名为my.cnf(名字规定必须是my.cnf)[root@Centos6 /usr/local/mysql]# vim /etc/mysql/my.cnf                          #编辑配置文件[mysqld]            #在[mysqld]里面添加如下三行代码,第一行是必须要加的,后两行是为了性能优化方便管理加的,可有可无datadir           = /var/lib/mysql/          #指明数据库存放路径innodb_file_per_table = on                   #使用的innodb数据库引擎,并且使每个表单独在一个文件里,方便管理skip_name_resolve  = on                      #为了加速访问速度,忽略地址的方向解析

4、创建系统数据库;

  #数据库被放置在/usr/local/mysql/scripts/mysql_install_db里,所以要跑脚本,使其生成数据库  #而且这个脚本一定不能进去scripts里跑,会出错,在它的上一层跑[root@Centos6 mysql]# scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql[root@Centos6 mysql]# ls /var/lib/mysql/                 #验证一下是否生成aria_log.00000001  mysql-bin.000001  mysql-bin.000004    testaria_log_control   mysql-bin.000002  mysql-bin.indexmysql              mysql-bin.000003  performance_schema[root@Centos6 mysql]#

5、启动服务;

[root@Centos6 mysql]# cp support-files/mysql.server /etc/init.d/mysqld    #将服务脚本放在特定的目录下[root@Centos6 mysql]# chkconfig --list mysqld                 #检查mysqld服务是否存在,如下所示,存在但启动(若不存在,就 chkconfig --add mysqld加上)mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off[root@Centos6 mysql]#service mysqld start                                        #启动服务,因为/var/log/mysqld.log已经存在所以直接成功Starting MySQL.171014 17:07:41 mysqld_safe Logging to '/var/log/mysqld.log'.171014 17:07:41 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql..                                                         [  OK  ][root@Centos6 mysql]#      #有些机器第一次启动失败,缺少日志文件(启动成功的下面的代码不用做)[root@Centos6 mysql]# mkdir /var/log/mariadb/             #那么就要单独创建一下[root@Centos6 mysql]# chown mysql /var/log/mariadb/       #为了给mysql对目录/var/log/mariadb/ 有写权限,所以将其目录的所有者改成mysql[root@Centos6 mysql]# service mysqld start          #再重启应该就没问题了

6、编辑PATH变量;

[root@Centos6 mysql]#  vim /etc/profile.d/mysql.sh           #单独放在一个配置文件里PATH=/usr/local/mysql/bin:$PATH[root@Centos6 mysql]# . /etc/profile.d/mysql.sh               #使其生效

7、初始化、跑安全脚本,设置口令密码;

[root@Centos6 mysql]# mysql_secure_installation               #安全脚本/usr/local/mysql/bin/mysql_secure_installation: line 393: find_mysql_client: command not foundNOTE: 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 currentpassword for the root user.  If you've just installed MariaDB, andyou 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):         #让输入密码,因为之前没有设,所以直接回车OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.
Set root password? [Y/n] y                                #是否设密码,跑安全脚本就是为了安全,所以“y”要设New password:                                            #输入密码Re-enter new password:                                   #再次输入密码Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.
Remove anonymous users? [Y/n] y                        #是否删除匿名用户,删除,这样就不能匿名登录了 ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n                 #是否禁止远程登录,不用禁止 ... skipping.By default, MariaDB comes with a database named 'test' that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.
Remove test database and access to it? [Y/n] n         #是否删除test数据库,删不删都行 ... skipping.Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y                   #使其立即生效 ... Success!Cleaning up...All done!  If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB![root@Centos6 mysql]#

三:实验测试;

[root@Centos6 mysql]# mysql -uroot -pmagedu            #-u接用户名,-p接密码(为了安全建议直接-p后回车再输入密码)Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 9Server version: 5.5.57-MariaDB MariaDB ServerCopyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> select user();                       #查看当前用户名(可参考Centos 7中http://13172997.blog.51cto.com/13162997/1972311)+----------------+| user()         |+----------------+| root@localhost |+----------------+1 row in set (0.01 sec)
MariaDB [(none)]> show databases;                   #显示数据库信息+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.09 sec)
MariaDB [(none)]> use mysql                    #设mysql为当前数据库Database changedMariaDB [mysql]> show tables;                 #显示当前数据库中的表信息+---------------------------+| Tables_in_mysql           |+---------------------------+| columns_priv              || db                        || event                     || func                      || general_log               || help_category             || help_keyword              || help_relation             || help_topic                || host                      || ndb_binlog_index          || plugin                    || proc                      || procs_priv                || proxies_priv              || servers                   || slow_log                  || tables_priv               || time_zone                 || time_zone_leap_second     || time_zone_name            || time_zone_transition      || time_zone_transition_type || user                      |+---------------------------+24 rows in set (0.00 sec)
MariaDB [mysql]> desc user    -> ;                             #不是mysql自身的命令必须加分号结束,此命令显示user表结构+------------------------+-----------------------------------+------+-----+---------+-------+| Field                  | Type                              | Null | Key | Default | Extra |+------------------------+-----------------------------------+------+-----+---------+-------+| Host                   | char(60)                          | NO   | PRI |         |       || User                   | char(16)                          | NO   | PRI |         |       || Password               | char(41)                          | NO   |     |         |       || Select_priv            | enum('N','Y')                     | NO   |     | N       |       || Insert_priv            | enum('N','Y')                     | NO   |     | N       |       || Update_priv            | enum('N','Y')                     | NO   |     | N  +------------------------+-----------------------------------+------+-----+---------+-------+42 rows in set (0.05 sec)MariaDB [mysql]> quitBye[root@Centos6 mysql]#

四:实验总结;

其实Centos 6中的安装和Centos 7 算是一样的步骤,只不过用的版本不一样而已;

Centos 7里说的稍微细一些,可以参考我的上篇文章http://13172997.blog.51cto.com/13162997/1972311




本文出自 “13162997” 博客,请务必保留此出处http://13172997.blog.51cto.com/13162997/1972389

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值