linux 二进制
MariaDB 数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用 GPL 授权许可 MariaDB 的目的是完全兼容 MySQL。基于事务的 Maria 存储引擎,替换了 MySQL 的 MyISAM 存储引擎。虽然 MariaDB 被视为 MySQL 数据库的替代品,但它在扩展功能、存储引擎以及一些新的功能改进方面都强过 MySQL。而且从 MySQL 迁移到 MariaDB 也是非常简单的。
详情点击 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://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 .
初始化脚本。使用
初始化数据库,使用 --user 定义数据库名称,--basedir 定义软件主目录,--datadir 定义数据库的存放目录,初始化完成后,将 mysql 的配置文件拷贝一份到 my.cnf 下。然后通过软件包提供的启动脚本 mysql.server 来管理服务进程并启动。
- mysql_install_db
- # 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
总结:被启动这个问题困扰了大概好几个小时。期间查询网上信息,未果。最后请教老师,被这一条语句所折服。这就足以看出经验的重要性了。
来源: http://www.bubuko.com/infodetail-2270204.html