Centos 6中安装二进制数据库最新版本mariadb-5.5.57
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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用户;
[[email protected] ~]# getent passwd mysql #先查看一下该用户是否存在,若存在就不用动,若不存在就创建 [[email protected] ~]# useradd -d /var/lib/mysql -r -m -s /sbin/nologin mysql #Centos 7里我将数据库放在了/app/mysqldb下了,这里就放在/var/log/mysql下吧
2、解压缩;
[[email protected] ~]# tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/ #因为是已经编译好的二进制文件,目录是已经被制定好的,必须放在/usr/local,故加上-C解压缩到指定目录 [[email protected] ~]# cd /usr/local/ #进入到该目录下 [[email protected] /usr/local]# ls bin games lib libexec share etc include lib64 mariadb-5.5.57-linux-x86_64 sbin src [[email protected] /usr/local]# ln -s mariadb-5.5.57-linux-x86_64/ mysql #因为名字必须是mysql,所以将其创建软链接 [[email protected] /usr/local]# cd mysql/ #然后进到mysql目录下
3、创建my.cnf配置文件
[[email protected] /usr/local/mysql]# mkdir /etc/mysql/ #编译时默认配置文件放在/etc/mysql下,所以创建一个mysql的目录 [[email protected] /usr/local/mysql]# ls support-files/ #二进制文件里已经定义好的配置文件放在/usr/local/mysql/support-files/下 binary-configure my-large.cnf mysql-log-rotate magic my-medium.cnf mysql.server my-huge.cnf my-small.cnf SELinux my-innodb-heavy-4G.cnf mysqld_multi.server [[email protected] /usr/local/mysql]# cp support-files/my-huge.cnf /etc/mysql/my.cnf #将二进制文件里的配置文件(里面有好几个,可以选择其中一个)复制到/etc/mysql/下,并改名为my.cnf(名字规定必须是my.cnf) [[email protected] /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里跑,会出错,在它的上一层跑 [[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql [[email protected] mysql]# ls /var/lib/mysql/ #验证一下是否生成 aria_log.00000001 mysql-bin.000001 mysql-bin.000004 test aria_log_control mysql-bin.000002 mysql-bin.index mysql mysql-bin.000003 performance_schema [[email protected] mysql]#
5、启动服务;
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld #将服务脚本放在特定的目录下 [[email protected] mysql]# chkconfig --list mysqld #检查mysqld服务是否存在,如下所示,存在但启动(若不存在,就 chkconfig --add mysqld加上) mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off [[email protected] 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 ] [[email protected] mysql]# #有些机器第一次启动失败,缺少日志文件(启动成功的下面的代码不用做) [[email protected] mysql]# mkdir /var/log/mariadb/ #那么就要单独创建一下 [[email protected] mysql]# chown mysql /var/log/mariadb/ #为了给mysql对目录/var/log/mariadb/ 有写权限,所以将其目录的所有者改成mysql [[email protected] mysql]# service mysqld start #再重启应该就没问题了
6、编辑PATH变量;
[[email protected] mysql]# vim /etc/profile.d/mysql.sh #单独放在一个配置文件里 PATH=/usr/local/mysql/bin:$PATH [[email protected] mysql]# . /etc/profile.d/mysql.sh #使其生效
7、初始化、跑安全脚本,设置口令密码;
[[email protected] mysql]# 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): #让输入密码,因为之前没有设,所以直接回车 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 #是否设密码,跑安全脚本就是为了安全,所以“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 #是否删除匿名用户,删除,这样就不能匿名登录了 ... 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 #是否禁止远程登录,不用禁止 ... 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 #是否删除test数据库,删不删都行 ... skipping. Reloading the privilege tables will ensure that all changes made so far will 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 MariaDB installation should now be secure. Thanks for using MariaDB! [[email protected] mysql]#
三:实验测试;
[[email protected] mysql]# mysql -uroot -pmagedu #-u接用户名,-p接密码(为了安全建议直接-p后回车再输入密码) Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 5.5.57-MariaDB MariaDB Server Copyright (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() | +----------------+ | [email protected] | +----------------+ 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 changed MariaDB [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]> quit Bye [[email protected] mysql]#
四:实验总结;
其实Centos 6中的安装和Centos 7 算是一样的步骤,只不过用的版本不一样而已;
Centos 7里说的稍微细一些,可以参考我的上篇文章http://13172997.blog.51cto.com/13162997/1972311
本文出自 “13162997” 博客,请务必保留此出处http://13172997.blog.51cto.com/13162997/1972389
以上是关于Centos 6中安装二进制数据库最新版本mariadb-5.5.57的主要内容,如果未能解决你的问题,请参考以下文章
在 Centos 6.6 docker 容器中安装厨师服务器
在虚拟机(VMware)中安装Linux CentOS 6.4系统(图解) 转