微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mysql-secure-installation错误-套接字

如何解决mysql-secure-installation错误-套接字

我在尝试进行MysqL-secure-installation时遇到错误错误:无法通过套接字“ /var/run/MysqLd/MysqLd.sock”连接到本地MysqL服务器(2) 命令'/ bin / sh -c DEBIAN_FRONTEND = noninteractive && MysqL_secure_installation --user root --host localhost'返回非零代码:1

我使用以下dockerfile并以这种方式构建映像:sudo docker build -t hello。

FROM debian:buster
RUN apt-get -y update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get install -y Nginx PHP PHP-fpm wget
RUN unlink /etc/Nginx/sites-enabled/default && mv /etc/Nginx/sites-available/default /etc/Nginx/sites-available/default_old
copY default_Nginx /etc/Nginx/sites-available/default
RUN rm -rf /etc/Nginx/sites-enabled/default && ln -s /etc/Nginx/sites-available/default /etc/Nginx/sites-enabled/default
RUN cd /etc/Nginx/ && mkdir ssl && openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/Nginx/ssl/Nginx.key -out /etc/Nginx/ssl/Nginx.crt -subj "/C=FR/ST=Ile-de-France/L=Paris/O=42/OU=clde-ber/CN=helloworld"
RUN cd /var/www/html/ && wget https://files.PHPmyadmin.net/PHPMyAdmin/5.0.2/PHPMyAdmin-5.0.2-english.tar.gz && tar -xvzf PHPMyAdmin-5.0.2-english.tar.gz && mv PHPMyAdmin-5.0.2-english PHPmyadmin && rm PHPMyAdmin-5.0.2-english.tar.gz
copY config_PHP var/www/html/PHPmyadmin/config.inc.PHP
RUN rm /etc/PHP/7.3/fpm/PHP.ini
copY PHP.ini /etc/PHP/7.3/fpm/PHP.ini
##RUN apt-get -y update && apt-get -y install PHP7.3-MysqL
## doute sur démarrage de PHPfpm
##RUN cd /var/www/html/ && wget http://repo.MysqL.com/MysqL-apt-config_0.8.13-1_all.deb
##RUN DEBIAN_FRONTEND=noninteractive dpkg -i MysqL-apt-config_0.8.13-1_all.deb
RUN apt-get -y update && apt-get -y install PHP7.3-MysqL
RUN cd /var/www/html/ && apt-get -y update && apt-get -y install gnupg lsb-release && wget https://dev.MysqL.com/get/MysqL-apt-config_0.8.15-1_all.deb && DEBIAN_FRONTEND=noninteractive dpkg -i  MysqL-apt-config_0.8.15-1_all.deb && DEBIAN_FRONTEND=noninteractive apt -y update && DEBIAN_FRONTEND=noninteractive apt -y install MysqL-server 
##RUN touch /var/run/MysqLd/MysqLd.sock && ln -s /var/run/MysqLd/MysqLd.sock /tmp/MysqLd.sock && chmod 0755 /var/run/MysqLd && chown MysqL:root /var/run/MysqLd
##RUN rm /etc/MysqL/my.cnf
##copY my.cnf /etc/MysqL/my.cnf
RUN DEBIAN_FRONTEND=noninteractive && MysqL_secure_installation --user root --host localhost
##RUN cd /var/www/html/ && apt-get -y update && apt-get -y install gnupg && apt -y update && apt -y install default-MysqL-server
RUN cd /var/www/html/ && wget https://wordpress.org/latest.tar.gz && tar -xzvf latest.tar.gz && touch .htaccess && chmod 660 .htaccess
RUN cd /var/www/html/wordpress/ && rm wp-config-sample.PHP
copY wp-config.php /var/www/html/wordpress/
RUN cp -a /var/www/html/wordpress/. /var/www/html && cd /var/www/html && rm -rf wordpress
RUN cd /var/www/html/ && mkdir wp-content/upgrade
RUN cd /var/www/html/ && chown -R root:www-data /var/www/html && find /var/www/html -type d -exec chmod g+s {} \; && chmod g+w /var/www/html/wp-content && chmod -R g+w /var/www/html/wp-content/themes && chmod -R g+w /var/www/html/wp-content/plugins
RUN cd /var/www/html/ && wget https://api.wordpress.org/secret-key/1.1/salt/
RUN cd /var/www/html/ && rm index.html
copY index.html /var/www/html/
##RUN service wordpress start
copY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
##RUN cd /var/run/MysqLd && touch MysqLd.sock && chmod +x MysqLd.sock
##RUN service MysqLd start
RUN chmod +x /usr/bin/docker-entrypoint.sh
##RUN MysqL /run/MysqLd -h localhost -u root --skip-password
##RUN service MysqLadmin start
##RUN cd /var/run/MysqLd && touch MysqLd.sock && chmod +x MysqLd.sock && chown MysqL:MysqL -R * && cd /tmp && ln -s /var/run/MysqLd/MysqLd.sock MysqLd.sock
##RUN echo "CREATE DATABASE wordpress DEFAULT CHaraCTER SET utf8 COLLATE utf8_unicode_ci;" | MysqLadmin -u root --bind-address=localhost status
##RUN echo "GRANT ALL ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY '';" | MysqLadmin -u root --bind-address=localhost status
##RUN echo "FLUSH PRIVILEGES;" | MysqLadmin -u --bind-address=localhost status
ENTRYPOINT bash docker-entrypoint.sh

我的docker-entrypoint.sh:

service Nginx start
Nginx -g daemon off;
service PHP7.3-fpm start
service MysqL start
bash

任何人都可以帮忙吗?

解决方法

我对dockerfile和入口点脚本进行了一些修改,因此它现在可以工作了。为了以root用户身份运行mysqld,我使用了该命令:

`mysqld --pid-file=/var/run/mysqld/mysqld.pid --user=root -D` 

所以我的pid文件不再位于可访问的/ tmp /文件夹中,而是其他位置。然后,要连接数据库,我修改了php.ini文件,添加了以下几行:

mysqli.default_socket =/run/mysqld/mysqld.sock
mysqli.default_host = localhost
mysqli.default_user = root

我必须将其添加到wp-config.php文件中:

`define('WP_ALLOW_REPAIR',true);

这是已知的dockerfile:

FROM debian:buster

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get -y update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get install -y nginx php php-fpm wget
RUN apt-get install -y php7.3-mysql
RUN apt-get -y install apt-utils

RUN unlink /etc/nginx/sites-enabled/default && mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default_old
COPY default_nginx /etc/nginx/sites-available/default
RUN rm -rf /etc/nginx/sites-enabled/default && ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
RUN cd /etc/nginx/ && mkdir ssl
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out \
/etc/nginx/ssl/nginx.crt -subj "/C=FR/ST=Ile-de-France/L=Paris/O=42/OU=clde-ber/CN=helloworld"

RUN cd /var/www/html/ && wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-english.tar.gz \
&& tar -xvzf phpMyAdmin-5.0.2-english.tar.gz && mv phpMyAdmin-5.0.2-english phpmyadmin && rm phpMyAdmin-5.0.2-english.tar.gz
COPY config_php var/www/html/phpmyadmin/config.inc.php
RUN rm /etc/php/7.3/fpm/php.ini
COPY php.ini /etc/php/7.3/fpm/php.ini

RUN apt-get -y update && apt-get -y install libsasl2-2 libaio1 libmecab2 libnuma1 perl && cd /var/lib/ && wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-common_8.0.22-1debian10_amd64.deb && \
dpkg -i mysql-common_8.0.22-1debian10_amd64.deb && \ 
wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client-plugins_8.0.22-1debian10_amd64.deb && dpkg -i \
mysql-community-client-plugins_8.0.22-1debian10_amd64.deb && \
wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/libmysqlclient21_8.0.22-1debian10_amd64.deb && dpkg -i libmysqlclient21_8.0.22-1debian10_amd64.deb && \ 
wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/libmysqlclient-dev_8.0.22-1debian10_amd64.deb \
&& dpkg -i libmysqlclient-dev_8.0.22-1debian10_amd64.deb && \
wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client-core_8.0.22-1debian10_amd64.deb && \
dpkg -i mysql-community-client-core_8.0.22-1debian10_amd64.deb && \
wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client_8.0.22-1debian10_amd64.deb && \
dpkg -i mysql-community-client_8.0.22-1debian10_amd64.deb && \
wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-client_8.0.22-1debian10_amd64.deb \
&& dpkg -i mysql-client_8.0.22-1debian10_amd64.deb && wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-server-core_8.0.22-1debian10_amd64.deb \
&& dpkg -i mysql-community-server-core_8.0.22-1debian10_amd64.deb && \
wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-server_8.0.22-1debian10_amd64.deb && \
dpkg -i mysql-community-server_8.0.22-1debian10_amd64.deb && wget https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-server_8.0.22-1debian10_amd64.deb && \
dpkg -i mysql-server_8.0.22-1debian10_amd64.deb 
RUN apt-get -y update && apt-get -y install mysql-server 

RUN cd /var/www/html/ && wget https://wordpress.org/latest.tar.gz && tar -xzvf latest.tar.gz && touch .htaccess && chmod 660 .htaccess
RUN cd /var/www/html/wordpress/ && rm wp-config-sample.php
COPY wp-config.php /var/www/html/wordpress/
RUN cp -a /var/www/html/wordpress/. /var/www/html && cd /var/www/html && rm -rf wordpress
RUN cd /var/www/html/ && mkdir wp-content/upgrade
RUN cd /var/www/html/ && chown -R root:www-data /var/www/html && find /var/www/html -type d -exec chmod g+s {} \; \
&& chmod g+w /var/www/html/wp-content && chmod -R g+w /var/www/html/wp-content/themes && chmod -R g+w /var/www/html/wp-content/plugins
RUN cd /var/www/html/ && wget https://api.wordpress.org/secret-key/1.1/salt/
RUN cd /var/www/html/ && rm index.html
COPY index.html /var/www/html/

COPY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
RUN chmod +x /usr/bin/docker-entrypoint.sh
ENTRYPOINT bash docker-entrypoint.sh

这是已知的入口点脚本:

mysqld --pid-file=/var/run/mysqld/mysqld.pid --user=root -D
echo "CREATE DATABASE wordpress;" | mysql --port=13306 --host=localhost --user=root
echo "USE wordpress;" | mysql --port=13306 --host=localhost --user=root
echo "GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' WITH GRANT OPTION;" | mysql --port=13306 --host=localhost --user=root
echo "update mysql.user set plugin='mysql_native_password' where user='root';" | mysql --port=13306 --host=localhost --user=root
echo "FLUSH PRIVILEGES;" | mysql --port=13306 --host=localhost --user=root
service nginx start
nginx -g daemon off;
service php7.3-fpm start
bash

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。