================================
©Copyright 蕃薯耀 2021-12-31
https://www.cnblogs.com/fanshuyao/
centos7 mysql --initialize 后启动mysql(service mysqld start)报错:Unit not found.
Failed to start mysql.server.service: Unit not found.
在CentOS 7中已经不在支持mysql(建议改使用MariaDB),就算已经安装,但CentOS7系统中(/usr/lib/systemd/system)是没有该服务的。
为什么不支持了呢?
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可
。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,
因此社区采用分支的方式来避开这个风险。
Centos 7默认是已经安装了MariaDB的,如果没有,可自行安装。
#安装mariadb yum install mariadb-server -y #启动服务 systemctl start mariadb.service #设置开机启动 systemctl enable mariadb.service #登录mysql mysql -uroot -p
(1)进入/usr/lib/systemd/system目录
cd /usr/lib/systemd/system
(2)创建mysqld.service文件
vi mysqld.service
(3)mysqld.service文件内容
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql Type=forking # Start main service ExecStart=/usr/bin/mysqld --defaults-file=/etc/mysql/my.cnf # Sets open_files_limit LimitNOFILE = 5000
下面的rpm方式安装mysql自动生成的mysqld.service,供参考:
[Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql Type=forking PIDFile=/var/run/mysqld/mysqld.pid # Disable service start and stop timeout logic of systemd for mysqld service. TimeoutSec=0 # Execute pre and post scripts as root PermissionsStartOnly=true # Needed to create system tables ExecStartPre=/usr/bin/mysqld_pre_systemd # Start main service ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS # Use this to switch malloc implementation EnvironmentFile=-/etc/sysconfig/mysql # Sets open_files_limit LimitNOFILE = 5000 Restart=on-failure RestartPreventExitStatus=1 PrivateTmp=false
(4)重新加载系统服务
systemctl daemon-reload
(5)Mysql设置开机启动,并启动mysql服务
systemctl enable mysqld.service systemctl start mysqld.service
查看Mysql状态
systemctl status mysqld.service service mysqld status
(1)先安装wget工具,有了可省略
yum -y install wget
(2)获取mysql5.7下载的镜像
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
没有该镜像,在安装Mysql时(yum -y install mysql-server)会报错:
没有可用软件包 mysql-server。
(3)rpm 方式安装Mysql镜像
rpm -ivh mysql57-community-release-el7-7.noarch.rpms
或者?
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
(4)安装Mysql服务
yum -y install mysql-server
或者?
yum install -y mysql-community-server
(时间宝贵,分享不易,捐赠回馈,^_^)
================================
©Copyright 蕃薯耀 2021-12-31
https://www.cnblogs.com/fanshuyao/