当前位置: 代码迷 >> 综合 >> Manjaro 安装 MySQL
  详细解决方案

Manjaro 安装 MySQL

热度:59   发布时间:2023-11-03 12:20:30.0

Manjaro 版本:20.0.3 Lysia
MySQL 版本:8.0.21

安装MySQL

引用自 manjaro安装mysql

sudo su
sudo pacman -S mysql
# 初始化MySQL,记住输出的root密码
mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
# 设置开机启动MySQL服务
systemctl enable mysqld.service
systemctl daemon-reload
systemctl start mysqld.service
# 使用MySQL前必须修改root密码,MySQL 8.0.15不能使用set password修改密码
mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
# 完成

遇到的问题

在初始化 MySQL 时出现以下错误

2020-07-31T11:23:19.936582Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-07-31T11:23:19.936658Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 13951
2020-07-31T11:23:19.938797Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2020-07-31T11:23:19.938809Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-07-31T11:23:19.938903Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-07-31T11:23:19.939025Z 0 [System] [MY-010910] [Server] /usr/bin/mysqld: Shutdown complete (mysqld 8.0.21)  Source distribution.

然后参考这篇文章: Manjaro中MySQL 8 的安装 – Gnome桌面
解决了问题,如下:

上面的主要 [Error] 信息为:

The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.

需要我们删除 /'var/lib/mysql/ 文件夹下的所有文件,输入如下命令,先删除所有文件夹,然后删除所有文件:

rm -rf /var/lib/mysql/*  
cd /var/lib/
rm -rf mysql/*

再次初始化

mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql

输出如下日志

2020-07-31T11:27:33.047730Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-07-31T11:27:33.047842Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 14406
2020-07-31T11:27:33.057992Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-31T11:27:39.916904Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-31T11:27:46.729463Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =_QFeBK:!8fw

可以看到第五行有初始化的密码,我的是: =_QFeBK:!8fw

然后设置开机启动 MySQL 服务

# 设置开机启动MySQL服务
systemctl enable mysqld.service
systemctl daemon-reload
systemctl start mysqld.service

进入 MySQL,如下下面一行命令后,输入密码

mysql -u root -p

MySQL 中修改默认密码,我将密码修改为 Admin123

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Admin123';

OK,完成。

  相关解决方案