Linux安装mariadb二进制版本

来源:互联网 发布:山东工商学院网络党课 编辑:程序博客网 时间:2024/05/22 03:16

上一篇说了mariadb编译安装过程,但在生产环境中一般使用发布好的二进制版本,由于安装过程和之前一样,不再详细叙述,只是简单概括一下安装过程:

  1. 下载 地址为:https://downloads.mariadb.org/

  这里选择最新版本的10.1.19稳定版,进入后根据计算机位数选择,这里下载适用于64位操作系统的Linux x86_64版本

  

  这里下载包含glibc和不包含glibc的都是可以的,如果下载包含glibc的,那么系统的glibc版本要满足要求,这里要大于2.14,一般系统是可以满足的

  下载之后上传到服务器准备安装

  2. 释放安装包 假设安装位置是/usr/local/mariadb 包名为:mariadb-10.1.19-linux-x86_64.tar.gz

tar -xvzf mariadb-10.1.19-linux-x86_64.tar.gzmv mariadb-10.1.19-linux-x86_64 /usr/local/mariadb/cd /usr/local/mariadb

  注意不要提前建立/usr/local/mariadb目录,直接放过去即可

  3. 相关配置

  备份原有mysql配置: mv /etc/my.cnf /etc/my.cnf.bak 

  在mariadb安装目录下的support-files有好几种配置模板,已经配置好的部分参数,分别用于不同的环境,这里简要说明一下:

  my-small.cnf 这个是为小型数据库或者个人测试使用的,不能用于生产环境

  my-medium.cnf 这个适用于中等规模的数据库,比如个人项目或者小型企业项目中,

  my-large.cnf 一般用于专门提供SQL服务的服务器中,即专门运行数据库服务的主机,配置要求要更高一些,适用于生产环境

  my-huge.cnf 用于企业级服务器中的数据库服务,一般更多用于生产环境使用

  所以根据以上几个文件,如果个人使用或者测试,那么可以使用前两个模板;企业服务器或者64G以上的高配置服务器可以使用后面两个模板,另外也可以根据自己的需求来加大参数和扩充配置获得更好的性能

  这里暂时使用my-small.cnf,复制配置文件: cp support-files/my-small.cnf /etc/my.cnf  

  编辑配置文件: vim /etc/my.cnf 在[mysqld]块中添加basedir全局目录将默认的数据目录,日志目录,pid文件都放置在basedir目录下,配置如下:

basedir = /usr/local/mariadb

  

  配置完成,保存并退出

  初次安装,要创建mysql用户和组,并给当前目录赋予权限:

groupadd mysqluseradd -r -g mysql -s /sbin/nologin mysqlchown -R mysql .chgrp -R mysql .

  然后执行初始化安装: ./scripts/mysql_install_db --user=mysql 

  调整权限:

chown -R root .chown -R mysql data/

  启动脚本: bin/mysqld_safe --user=mysql & 

  添加mysql到系统服务目录: cp support-files/mysql.server /etc/init.d/mysqld 

  如果是之前安装过mysql,那么现在就已经启动了,第一次安装需要手动启动服务: /etc/init.d/mysqld start 

  添加mysqld到系统服务,随系统一起启动: chkconfig mysqld on 

  查看mysql服务运行状态: systemctl status mysqld.service 

  后续的所有的操作和之前mysql就完全一致了


初始化配置

/usr/local/mariadb/bin/mysql_secure_installation --basedir=/usr/local/mariadb


 

问题解答:FATAL ERROR: Could not find ./bin/my_print_defaults 解决方法


网上很多方法都是:/usr/local/mysql/scripts/mysql_install_db --user=mysql

但是很有可能报错,找不到bin目录中的my_print_defaults
错误信息: 
FATALERROR:Couldnotfind./bin/my_print_defaults
If you are using a binary release, you must run this script from
within the directory the archive extracted into. If you compiled
MySQL yourself you must run 'make install' first. 
       或
[root@bogon scripts]# /usr/local/mysql/scripts/mysql_install_db --user=mysql&
[1] 16874
[root@bogon scripts]#
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
 
解决方法:
 [root@bogon scripts]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &(这点非常重要)


问题:解决bash: mysql: command not found 的方法

原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
首先得知道mysql命令或mysqladmin命令的完整路径,比如mysql的路径是:/usr/local/mysql/bin/mysql,我们则可以这样执行命令:

# ln -s  /usr/local/mysql/bin/mysql  /usr/bin


问题:解决软连接ln报错-bash: /usr/local/bin/mysql: Too many levels of symbolic links

使用一下命令软连接以后在使用时报错:

cd /temp

ln -s logs /data/logs

cd /data/logs

touch test

-bash: /usr/local/bin/mysql: Too many levels of symbolic links

解决办法,建立软连接的时候一定要使用绝对路径,更改一下命令就好了

rm -rf /data/logs

ln -s /temp/logs /data/logs

QQ截图20140122132358