Mariadb mysql_install_db安装系统表报FATAL ERROR: Could not find my_print_defaults错误

问题描述

YUM安装完成mariadb 10.2.43,执行systemctl start mariadb报:FATAL ERROR: Could not find my_print_defaults,查看错误日志:

2022-03-29  9:22:31 140042083666112 [Note] Plugin 'FEEDBACK' is disabled.
2022-03-29  9:22:31 140042083666112 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2022-03-29  9:22:31 140040631072512 [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
2022-03-29  9:22:31 140042083666112 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2022-03-29  9:22:31 140042083666112 [Note] Server socket created on IP: '::'.
2022-03-29  9:22:31 140042083666112 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

发现没有系统表,按照报错里提示的文档地址(https://mariadb.com/kb/en/mysql_install_db/#options),使用mysql_install_db进行系统表安装:

# 注意--defaults-file=/etc/my.cnf.d/my.cnf必须排在首位
mysql_install_db --defaults-file=/etc/my.cnf.d/my.cnf --datadir=/home/mysql --basedir=/home/mysql --user=mysql

执行后提示报错:Could not find my_print_defaults,找不到Could not find my_print_defaults这个文件

FATAL ERROR: Could not find my_print_defaults

The following directories were searched:

    /home/mysql/bin
    /home/mysql/extra

If you compiled from source, you need to either run 'make install' to
copy the software into the correct location ready for operation.
If you don't want to do a full install, you can use the --srcdir
option to only install the mysql database and privilege tables.

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.

The latest information about mysql_install_db is available at
https://mariadb.com/kb/en/installing-system-tables-mysql_install_db

查找/usr/bin确实有这个文件

[root@pev bin]# ls -l /usr/bin/ |grep my
-rwxr-xr-x    1 root root       1446 Feb 11 02:29 msql2mysql
-rwxr-xr-x    1 root root        206 Oct 11 10:25 mycli
-rwxr-xr-x    1 root root    4079120 Feb 11 02:57 myisamchk
-rwxr-xr-x    1 root root    3950560 Feb 11 02:57 myisam_ftdump
-rwxr-xr-x    1 root root    3932776 Feb 11 02:57 myisamlog
-rwxr-xr-x    1 root root    3975952 Feb 11 02:57 myisampack
-rwxr-xr-x    1 root root    3578800 Feb 11 02:57 my_print_defaults

百度一下,说是必须绝对路径执行,执行了一下,还是不行。

/usr/bin/mysql_install_db --defaults-file=/etc/my.cnf.d/my.cnf --datadir=/home/mysql --basedir=/home/mysql --user=mysql

如何解决

无意间看到了官方文档里的安装提示:
在这里插入图片描述

注释掉my.cnf里自定义目录

[mysqld]
# basedir = /home/mysql         # 安装目录
# datadir = /home/mysql         # 数据库存文件放路径

然后执行一下mysql_install_db --user=mysql
直接安装成功。。。。

[root@pev mysql]# mysql_install_db --user=mysql
 mysql_install_db --user=mysql
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following command:

'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.

Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

在起服务,正常

root@pev mysql]# systemctl start mariadb
[root@pev mysql]# systemctl status mariadb
● mariadb.service - MariaDB 10.2.43 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─limits.conf, migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2022-03-29 10:40:08 CST; 21s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 26836 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 26734 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  Process: 26731 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 26802 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─26802 /usr/sbin/mysqld --basedir=/usr

如果想迁移到另外的目录,请参考本人的另外一篇文档:Mariadb 冷迁库https://blog.csdn.net/hzcm1984/article/details/116158129

问题原因

my.cnf配置问题
如果你在my.cnf里配置了自定义安装目录,yum时和mysql_install_db里默认的安装目录/var/lib/mysql不一致,就会报文章开头的错

# 自定义按照目录
[mysqld]
basedir = /home/mysql         # 安装目录
datadir = /home/mysql         # 数据库存文件放路径

编辑 /usr/bin/mysql_install_db,发现lddata="/var/lib/mysql"yum时已经默认好了


basedir=""
builddir=""
ldata="/var/lib/mysql"
langdir=""
srcdir=""

总结

yum安装时建议还是使用默认安装目录(不止mariadb),因为RPM包在编译时已经定义好了安装目录,如果此时在强制更换安装目录,则有可能出现安装失败。
以上问题可以使用源码手动编译,指定安装目录,或者在安装成功后通过配置文件再次进行修改即可

参考文章

https://mariadb.com/kb/en/mysql_install_db/#options

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值