mysql_secure_installation "无法通过套接字连接到本地 MySQL 服务器"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15439307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql_secure_installation "Can't connect to local MySQL server through socket"
提问by vidyadhar
When I am invoking the file mysql_secure_installation
I get an error like
当我调用文件时,mysql_secure_installation
我收到类似的错误
[mysqk123@InstallZeMo bin]$ ./mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Enter current password for root (enter for none):
but the given sock file in my.cnf file is /home/mysqk123/tmp/mysql.sock and I am using redhat linux 5.3 and mysql 5.1.47
但是 my.cnf 文件中给定的 sock 文件是 /home/mysqk123/tmp/mysql.sock 并且我使用的是 redhat linux 5.3 和 mysql 5.1.47
I know that the tasks performed by mysql_secure_installation script can be performed manually but here I have to run the script [ not allowed to do the task manually ]
我知道 mysql_secure_installation 脚本执行的任务可以手动执行,但在这里我必须运行脚本[不允许手动执行任务]
采纳答案by RandomSeed
Since this utility is meant to be used over a standard installation, and because it seems to accept no parameter, I see very few options:
由于此实用程序旨在用于标准安装,并且似乎不接受任何参数,因此我看到的选项很少:
- temporarily configure MySQL to use the default socket location for the time of the procedure (alternatively, a symbolic link from the default location to your custom location might just work).
- modify the script
mysql_secure_installation
so that it uses your custom location. If I understand it correctly, the script creates a temporary configuration file as./.my.cnf.$$
($$
is the pid) around line 46 in themake_config
subroutine.
- 临时配置 MySQL 以在过程中使用默认套接字位置(或者,从默认位置到自定义位置的符号链接可能会起作用)。
- 修改脚本
mysql_secure_installation
,使其使用您的自定义位置。如果我理解正确,脚本会在子例程中的第 46 行附近创建一个临时配置文件./.my.cnf.$$
($$
是 pid)make_config
。
Modify as follows: (disclaimer: not tested :)
修改如下:(免责声明:未测试:)
make_config() {
echo "# mysql_secure_installation config file" >$config
echo "[mysql]" >>$config
echo "user=root" >>$config
echo "password='$rootpass'" >>$config
# add the line below
echo "socket=/home/mysqk123/tmp/mysql.sock" >>$config
}
Again, this script is meant to be used on a standard, out-of-the box installation. Tell your boss (or your client) that if you were able to configure MySQL to use a non-standard socket location, you are also able to run by hand simple commands such as deleting accounts and setting passwords.
同样,此脚本旨在用于标准的、开箱即用的安装。告诉您的老板(或您的客户),如果您能够将 MySQL 配置为使用非标准套接字位置,您还可以手动运行简单的命令,例如删除帐户和设置密码。
回答by d-_-b
Make sure you start mysql or mariadb, for example:
确保你启动了 mysql 或 mariadb,例如:
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
回答by K M
The MySQL Socket declaration should be located under [mysqld]
in your my.cnf
(located at /etc/mysql/my.cnf
in Debian flavours). MySQL Socket information can also be found using the following command:
MySQL Socket 声明应位于[mysqld]
您的my.cnf
(位于/etc/mysql/my.cnf
Debian 风格)下。还可以使用以下命令找到 MySQL Socket 信息:
mysql> show variables like 'socket';
+-----------------------------------------+-------------------------------+
| Variable_name | Value |
+-----------------------------------------+-------------------------------+
| socket | /yourpath/mysql.sock |
+-----------------------------------------+-------------------------------+
1 rows in set (0.00 sec)
Update the environment variable for the current session and execute the command, eg:
更新当前会话的环境变量并执行命令,例如:
export MYSQL_UNIX_PORT=/home/mysql123/tmp/mysql.sock
./mysql_secure_installation
回答by Hymanet
You can also make a symlink to the socket file and then remove it:
您还可以创建指向套接字文件的符号链接,然后将其删除:
ln -s /home/mysqk123/tmp/mysql.sock /var/lib/mysql/mysql.sock
mysql_secure_installation # Do your stuff
rm -rf /var/lib/mysql/mysql.sock
回答by Tom Bisciglia
I had this same error happen, and it turns out I had stopped the MySQL service and forgotten to restart it. So you may want to check the status of the mysql service using a command like:
我发生了同样的错误,结果我停止了 MySQL 服务并忘记重新启动它。因此,您可能需要使用如下命令检查 mysql 服务的状态:
mysqladmin -u root -p status
mysqladmin -u root -p status
If you get an error, it means MySQL is not running, and you can start the MySQL service. Or, if you prefer, you can recklessly attempt to start the service without first checking its status (which won't work if it's already running) using one of these commands:
如果出现错误,则说明 MySQL 没有运行,您可以启动 MySQL 服务。或者,如果您愿意,您可以使用以下命令之一不顾一切地尝试启动该服务,而无需先检查其状态(如果它已经在运行,则该服务将无法运行):
/etc/init.d/mysql start
service mysql start
Replace mysqld
with mysqld
if your system is using that version of MySQL.
更换mysqld
用mysqld
,如果您的系统正在使用该版本的MySQL。