码迷,mamicode.com
首页 > 数据库 > 详细

二进制安装mariadb的奇妙经历

时间:2017-08-20 14:52:41      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:mariadb   linux   二进制   

二进制安装mariadb的奇妙经历

1. MariaDB介绍

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL。基于事务的Maria存储引擎,替换了MySQL的MyISAM存储引擎。虽然MariaDB被视为MySQL数据库的替代品,但它在扩展功能、存储引擎以及一些新的功能改进方面都强过MySQL。而且从MySQL迁移到MariaDB也是非常简单的。

详情点击mariadb官方站点

2. 二进制安装mariadb

下载二进制包:安装包:mariadb-10.2.8

# wget https://downloads.mariadb.org/interstitial/mariadb-10.2.8/bintar-linux-x86_64/mariadb-10.2.8-linux-x86_64.tar.gz/from/http%3A//mirrors.tuna.tsinghua.edu.cn/mariadb/

解压到/usr/local下

# tar -xvf index.html -C  /usr/local/

解压后的相关目录说明:

bin:            各种二进制都在此目录下
data:           如果我们不创建新目录的话,此目录就是默认的数据目录。所以权限必须是属主和属组都是mysql
docs:           相关 文档include:        头文件lib:            库文件man:            帮助手册
mysql-test:     mysql测试组件
scripts:        mysql初始化时要用到的脚本
share:          mysql的共享内容
sql-bench:      对mysql做压力测试工具
support-files:  mysql正常运行的样例性的配置文件或文档

做一个软连接。切换到mariadb目录下。并参考一个安装说明文档

# ln -s /usr/local/mariadb-10.2.8-linux-x86_64/ /usr/local/mysql
# cd /usr/local/mysql/
# vim INSTALL-BINARY
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysqlshell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &

创建mysql用户和组,并修改mariadb下的权限

# groupadd mysql
# useradd -r -s /sbin/nologin -g mysql mysql
# chown -R mysql.mysql .

初始化脚本。使用mysql_install_db初始化数据库,使用--user定义数据库名称,--basedir定义软件主目录,--datadir定义数据库的存放目录,初始化完成后,将mysql的配置文件拷贝一份到my.cnf下。然后通过软件包提供的启动脚本mysql.server来管理服务进程并启动。

# mkdir -p /data/
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
# cp support-files/my-small.cnf /etc/my.cnf
# cp -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# /etc/init.d/mysqld start
 Starting mysqld (via systemctl): 
 Warning: mysqld.service changed on disk. 
 Run ‘systemctl daemon-reload‘ to reload units.Job for mysqld.service 
 failed because the control process exited with error code. 
 See "systemctl status mysqld.service" and "journalctl -xe" for details.
                                                       [失败]

这时发现启动失败:查看日志,发现并没有什么有用的信息。

# systemctl status mysqld.service
# tail -f /var/log/messages
Aug 20 11:58:56 php systemd: Starting LSB: start and stop MySQL...
Aug 20 11:58:57 php mysqld: Starting MySQL.170820 11:58:57 mysqld_safe Logging to ‘/usr/local/mysql/data/php.err‘.
Aug 20 11:58:57 php mysqld: 170820 11:58:57 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/dataAug 20 11:58:57 php mysqld: ERROR!
Aug 20 11:58:57 php systemd: mysqld.service: control process exited,     code=exited status=1Aug 20 11:58:57 php systemd: Failed to start LSB: start and stop MySQL.
Aug 20 11:58:57 php systemd: Unit mysqld.service entered failed state.
Aug 20 11:58:57 php systemd: mysqld.service failed.

在查看/data/php.err日志:发现报错信息

# tail /usr/local/mysql/data/php.err 
2017-08-20 12:03:26 139715621869376 [ERROR] Can‘t open and lock privilege tables: Table ‘mysql.servers‘ doesn‘t exist
2017-08-20 12:03:26 139715621869376 [Note] Server socket created on IP: ‘::‘.
2017-08-20 12:03:26 139715621869376 [ERROR] Fatal error: Can‘t open and lock privilege tables: Table ‘mysql.user‘ doesn‘t exist

经过请教得:在配置文件my.cnf的[mysqld]下添加datadir = /data/mysql 指明数据库的路径。 就好了。重启成功。

# /etc/init.d/mysqld startStarting mysqld (via systemctl):                           [  确定  ]# ss -tnl|grep 3306LISTEN     0      80          :::3306                    :::*

配置好shell环境:

# PATH=$PATH:/usr/local/mysql/bin/
# echo "export PATH=$PATH:/usr/local/mysql/bin/">>/etc/profile

总结:被启动这个问题困扰了大概好几个小时。期间查询网上信息,未果。最后请教老师,被这一条语句所折服。这就足以看出经验的重要性了。


本文出自 “dianel简单不简单” 博客,请务必保留此出处http://dianel.blog.51cto.com/12170393/1957801

二进制安装mariadb的奇妙经历

标签:mariadb   linux   二进制   

原文地址:http://dianel.blog.51cto.com/12170393/1957801

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!