Centos7以上的版本 mysql 無法啟動,無法停止問題

 2023-10-09 阅读 17 评论 0

摘要:service mysqld start 始終提示如下: Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.systemctl start/stop mysqld.servicesystemctl start/stop mysql.service 死活都提示找不到。 使用 kill -9 pid 殺掉進程后࿰

service mysqld start

始終提示如下:

Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.


systemctl start/stop mysqld.service
systemctl start/stop mysql.service

死活都提示找不到。

使用 kill -9 pid 殺掉進程后,只是換了一個pid 又啟動了3306端口,

【你是不是用mysqld_safe起的mysql?這是個守護進程,用它起數據庫的話,直接kill它會檢測到數據庫非正常關閉,會自動嘗試起數據庫。你可以選擇先kill掉mysqld_safe的進程然后再kill mysql;或者使用這個命令:kill -9 `ps -ef | grep 'mysqld' | grep -v grep|awk '{print $2}'`】

?

無奈,網上搜索半天總算找到一個可以用的。 其實是默認的這個環境一起安裝了一個叫MariaDB的東西(可以把它理解為mysql的安全向導),幫助提高mysql的安全性。?

原文的思路如下,先查看mysql版本,發現是mysql是有的,但是為何提示不存在呢,那就一步步排查原因。?

后面就找到 etc/my.cnf 這個文件打開查看引用的各個路徑,也都一一找到了。 那這到底是為啥呢,這老外也是百思不得解,然后他也進行了搜索,搜到一篇stackoverflow的內容,就是安裝MariaDB之后,就找不到mysqld了。于是乎一樓的答案就給出了:

安裝MariaDB之后必須先啟動MariaDB才能啟動mysqld,其實就是運行一下MariaDB向導,它是個一次性的東東,就是幫助你提高mysql安全性的,詳細看這里:http://www.jb51.net/article/47727.htm

總結一下就是運行下面三句就搞定啦:

systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation

運行mysql_secure_installation。運行mysql_secure_installation會執行幾個設置:
? a)為root用戶設置密碼
? b)刪除匿名賬號
? c)取消root用戶遠程登錄
? d)刪除test庫和對test庫的訪問權限
? e)刷新授權表使修改生效

通過這幾項的設置能夠提高mysql庫的安全。建議生產環境中mysql安裝這完成后一定要運行一次mysql_secure_installation,詳細步驟請參看下面的命令:

?

MySQL service not running on CentOS 7 system

I had installed the?MariaDB, a?fork?of the?MySQL?relational database management system (RDBMS)?on a CentOS 7 system when I set up the system. When I checked the version of the software with the?mysql --version?command, I saw the following:

# mysql --version
mysql  Ver 15.1 Distrib 5.5.37-MariaDB, for Linux (x86_64) using readline 5.1

But, when I ran the?mysql?command on the system, I received the error message shown below:

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

I checked to see if the mysqld service was running and found it was not.

# systemctl status mysqld.service
mysqld.serviceLoaded: not-found (Reason: No such file or directory)Active: inactive (dead)

When I tried to start the service, it wouldn't start.

# service mysqld start
Redirecting to /bin/systemctl start  mysqld.service
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
# systemctl start mysqld.service
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.

I checked the contents of the?/etc/my.cnf?file and saw the following:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

I checked for the existence of files and directories listed in that file. I saw the following results for the locations for?datadir,?socket,?log-error, and?pid-file:

# ls -ld /var/lib/mysql
drwxr-xr-x. 19 mysql mysql 4096 Oct 14 23:46 /var/lib/mysql
[root@localhost install]# ls -l /var/lib/mysql/mysql.sock
srwxrwxrwx. 1 mysql mysql 0 Sep 29 15:05 /var/lib/mysql/mysql.sock
# ls -l /var/log/mariadb/mariadb.log
-rw-r-----. 1 mysql mysql 0 Oct  5 20:49 /var/log/mariadb/mariadb.log
# ls -l /var/run/mariadb/mariadb.pid
ls: cannot access /var/run/mariadb/mariadb.pid: No such file or directory

I didn't see any?mariadb.pid?file, but I wouldn't expect it to be created until the mysqld service successfully started.

When I checked the files in the?includedir?directory, I saw the following:

# ls -l /etc/my.cnf.d
total 12
-rw-r--r--. 1 root root 295 Apr 15  2014 client.cnf
-rw-r--r--. 1 root root 232 Apr 15  2014 mysql-clients.cnf
-rw-r--r--. 1 root root 744 Apr 15  2014 server.cnf

So I didn't know why I was getting the "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'" message when I issued the command?mysql?nor why my attempt to start the mySQL service failed with a "No such file or directory" message. Searching online, I found a posting by?danneth?at?No mysqld or mysql.server after mariadb-server install?to use?systemctl start mariadb.service. When I used that command, I didn't see any error messages. I tried thesystemctl startus mysqld service?after issuing the command, but still saw a error message for it. But, when I then issued the?mysql?command I received an "access denied" message this time, which seemed reasonable, since I hadn't provided the password for the root account when I issued the command..

# systemctl start mariadb.service
# systemctl status mysqld service
mysqld.serviceLoaded: not-found (Reason: No such file or directory)Active: inactive (dead)service.serviceLoaded: not-found (Reason: No such file or directory)Active: inactive (dead)# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

When I was using CentOS 5, I had MySQL rather than MariaDB and I didn't know I needed to start the MariaDB RDBMS service on the CentOS 7 system using a command referencing?mariadb?rather?mysqld. I assumed I could reference mysqld to start the service.

The history behind the creation of MariaDB can be found in the?history section of the Wikipedia article on MySQL. MariaDB was created by one of the cofounders of MySQL,?Michael Widenius, after?Oracle Corporation?obtained rights to the MySQL software from?Sun Microsystems.

To have the MariaDB service start automatically each time the system boots, issue the command?systemctl enable mariadb.service. After you have started the service, also issue the command?mysql_secure_installation.

# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS 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: NO)
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.You already have a root password set, so you can safely answer 'n'.Change the root password? [Y/n] n... skipping.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
ERROR 1146 (42S02) at line 1: Table 'mysql.servers' doesn't exist... Failed!Cleaning up...All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.Thanks for using MariaDB!

I had it remove the anonymous account, since leaving it would be a security vulnerability. I also chose to disallow remote root login to MariaDB and the test database for the same reason.

I had copied the contents of the?/var/lib/mysql?directory from the hard drive of the prior CentOS 5 system to the new CentOS 7 system to have all of the databases from the old system available on the new system, so that appeared to be the reason that the?mysql_secure_installation, which can be found in?/usr/bin, did not accept my just hitting?Enter?for the password initially. When I entered the root password for MySQL on the old system, it was accepted. And I was able finally get a prompt where I could enter SQL commands using that password with?mysql -u root -p?.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.37-MariaDB MariaDB ServerCopyright (c) 2000, 2014, Oracle, Monty Program Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

So the 3 steps to enable and run MariaDB are as follows, assuming it was previously installed during the initial setup for the system or with?yum install mariadb mariadb-server:

systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation

轉載于:https://www.cnblogs.com/beyang/p/9082119.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/134400.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息