SfTian ArchLinux安装MariaDB的正确姿势 ### ArchLinux是我近期在折腾的一个系统 但是因为刚接触这个系统所以就把自己踩过的坑和经验分享给大家 首先就是安装mariadb啦 ```bash pacman -S mariadb ``` 然后你心系若狂的执行了 ```bash mysql_secure_installation ``` 发现有件事请不对? ```log [root@SfTian deepin-wine-qq-arch]# mysql_secure_installation shell-init:获取当前目录时出错: getcwd: 无法访问父目录:没有那个文件或目录 touch: 无法 touch '.my.cnf.26886': 没有那个文件或目录 touch: 无法 touch '.mysql.26886': 没有那个文件或目录 chmod: 无法访问 '.my.cnf.26886': 没有那个文件或目录 chmod: 无法访问 '.mysql.26886': 没有那个文件或目录 NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): /usr/bin/mysql_secure_installation:行249: .my.cnf.26886: 没有那个文件或目录 /usr/bin/mysql_secure_installation:行250: .my.cnf.26886: 没有那个文件或目录 /usr/bin/mysql_secure_installation:行251: .my.cnf.26886: 没有那个文件或目录 /usr/bin/mysql_secure_installation:行253: .my.cnf.26886: 没有那个文件或目录 /usr/bin/mysql_secure_installation:行218: .mysql.26886: 没有那个文件或目录 /usr/bin/mysql_secure_installation:行220: .mysql.26886: 没有那个文件或目录 Enter current password for root (enter for none): ``` ### ??? 然后执行了 ```bash systemctl status mariadb ``` 发现了一件事 ```bash × mariadb.service - MariaDB 10.8.4 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; preset: disabled) Active: failed (Result: exit-code) since Tue 2022-08-23 07:15:54 CST; 5s ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Process: 27035 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 27037 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && sys> Process: 27063 ExecStart=/usr/bin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE) Main PID: 27063 (code=exited, status=1/FAILURE) Status: "MariaDB server is down" CPU: 299ms 8月 23 07:15:54 SfTian mariadbd[27063]: 2022-08-23 7:15:54 0 [ERROR] Could not open mysql.plugin table: "Table 'mysql.plugin' doesn't exist". Some plugins may> 8月 23 07:15:54 SfTian mariadbd[27063]: 2022-08-23 7:15:54 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist 8月 23 07:15:54 SfTian mariadbd[27063]: 2022-08-23 7:15:54 0 [Note] Server socket created on IP: '0.0.0.0'. 8月 23 07:15:54 SfTian mariadbd[27063]: 2022-08-23 7:15:54 0 [Note] Server socket created on IP: '::'. 8月 23 07:15:54 SfTian mariadbd[27063]: 2022-08-23 7:15:54 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.db' doesn't exist 8月 23 07:15:54 SfTian mariadbd[27063]: 2022-08-23 7:15:54 0 [ERROR] Aborting 8月 23 07:15:54 SfTian mariadbd[27063]: Warning: Memory not freed: 280 8月 23 07:15:54 SfTian systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE 8月 23 07:15:54 SfTian systemd[1]: mariadb.service: Failed with result 'exit-code'. 8月 23 07:15:54 SfTian systemd[1]: Failed to start MariaDB 10.8.4 database server. ``` 焯!这不是没初始化DB吗?裂开了 快快使用```mariadb-install-db``` 等会。。。 忘了一件事,如果这样弄的话就会出现 ```log [root@SfTian deepin-wine-qq-arch]# mariadb-install-db shell-init:获取当前目录时出错: getcwd: 无法访问父目录:没有那个文件或目录 mkdir: 无法创建目录 "./data": 没有那个文件或目录 Fatal error Can't create database directory './data' The latest information about mysql_install_db is available at https://mariadb.com/kb/en/installing-system-tables-mysql_install_db ``` 对,不出所料hhh 所以我们需要执行这样的指令 ```bash sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql ``` 对,没错这样就可以啦,然后只需要```mysql_secure_installation```正常安装就可以了hhh 这次踩过坑之后希望大家可以避免踩雷hhh 取消回复 发表新评论 提交评论