MariaDB 10.3 mysql8_Linux学习笔记(八):从MySQL 8.x到10.3.11-MariaDB

本文记录了在CentOS8上从MySQL 8.x迁移到MariaDB 10.3.11的过程,包括遇到的启动失败、包冲突问题及解决方法。通过调整用户和组、安装及配置mariadb-server、执行安全安装向导来确保数据库服务正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MySQL 配置

建立MySQL用户及用户组,方便单独管理。因为这个用户不需要直接登录Linux系统,所以无需设置密码。

命令:groupadd mysql

命令:useradd -g mysql mysql

命令:usermod -g mysql mysql #可选

命令:groupadds mysql

查看:mysql -V

CentOS8 运行MySQL失败

启动报错:[root@localhost singa]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[root@localhost singa]# service mysqld start

Redirecting to /bin/systemctl start mysqld.service

Failed to start mysqld.service: Unit mysqld.service not found.

[root@localhost singa]# systemctl start mariadb.service

Failed to start mariadb.service: Unit mariadb.service not found.

问题排查:当出现以上情况时,说明未安装Mariadb.server,在启动MySQL前会强制要求你启动Mariadb.server进行密码等设置

Mariadb.server 使用yum等方式安装失败[root@localhost singa]# yum install mariadb-server

上次元数据过期检查:0:00:47 前,执行于 2019年11月05日 星期二 15时15分58秒。

错误:

问题: problem with installed package mysql-8.0.17-3.module_el8.0.0+181+899d6349.x86_64package mysql-8.0.17-3.module_el8.0.0+181+899d6349.x86_64 conflicts with mariadb provided by mariadb-3:10.3.11-2.module_el8.0.0+35+6f2527ed.x86_64

package mariadb-3:10.3.11-2.module_el8.0.0+35+6f2527ed.x86_64 conflicts with mysql provided by mysql-8.0.17-3.module_el8.0.0+181+899d6349.x86_64

package mariadb-server-3:10.3.11-2.module_el8.0.0+35+6f2527ed.x86_64 requires mariadb(x86-64), but none of the providers can be installed

conflicting requests

package mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 is excluded

(try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

问题排查:当出现以上情况时,说明使用过yun install mysql这一命令安装过mysql,或者使用过LNMP等集成环境包,这些安装包没有及时更新mariadb-server服务,所以连接服务失效。mariadb-server服务类似于安装向导,用来配置简单的安全信息,CentOS环境下,MySQL-8.0强制优先配置。

解决办法:CentOS已提供支持We already supply both mysql and mariadb in the repos.

查看软件包命令:dnf list mysql-server mariadb-server

「尝试在命令行中添加『--allowerasing』以替换有冲突的软件包,或者『skip-broken』以跳过可卸载的软件包,或者『 --nobest』不仅使用最佳候选软件包」

安装命令:yum install mysql-server

安装命令:yum install mariadb-server --allowerasing

在补充完这两个软件包之后,MySQL和Mariadb即刻正常配置。

执行MySQL安全配置向导

命令:systemctl start mariadb.service

命令:systemctl enable mariadb.service

命令:mysql_secure_installation

[root@localhost singa]# mysql_secure_installation

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

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Enter current password for root (enter for none): #初次运行直接回车

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

# 以下全部选Y

Set root password? [Y/n] Y

New password: # 设置root用户密码

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] Y

... Success!

Normally, root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y

... Success!

By default, MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] Y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] Y

... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

启动命令:systemctl start mysql.service

查看启动状态:systemctl status mysqld.service

按q退出

[root@localhost singa]# mysql -V

mysql Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1

我懵了。

参考路过求个平安:护身符

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值