问题描述
YUM安装完成mariadb 10.2.43,执行systemctl start mariadb报:FATAL ERROR: Could not find my_print_defaults,查看错误日志:
2022-03-29 9:22:31 6112 [Note] Plugin 'FEEDBACK' is disabled. 2022-03-29 9:22:31 6112 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded 2022-03-29 9:22:31 2512 [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 6112 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist 2022-03-29 9:22:31 6112 [Note] Server socket created on IP: '::'. 2022-03-29 9:22:31 6112 [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 Feb 11 02:57 myisamchk -rwxr-xr-x 1 root root Feb 11 02:57 myisam_ftdump -rwxr-xr-x 1 root root Feb 11 02:57 myisamlog -rwxr-xr-x 1 root root Feb 11 02:57 myisampack -rwxr-xr-x 1 root root 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/
问题原因
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=""
总结
参考文章
https://mariadb.com/kb/en/mysql_install_db/#options
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/216029.html原文链接:https://javaforall.net
