Reading files in MySQL with file_priv = no

好吧,我是在法客上看到园长发的这篇文章,然后追到乌云,然后追到源头,觉得很是实用,所以就贴出来了。


All we know for reading files in MySQL we need file_priv permission.
But there is way for reading files without this permission.

We can create new table and fill this table with data from file:

LOAD DATA LOCAL INFILE '/etc/passwd' INTO TABLE test FIELDS TERMINATED BY '';
and
select * from test;


参考:http://sb.f4ck.org/thread-18477-1-1.html

      http://zone.wooyun.org/content/12175

      https://bugscollector.com/tricks/

PHP logo PHP Version 5.6.40 System Linux yfw.szrengjing.com 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64 Build Date May 12 2020 15:26:41 Configure Command './configure' '--prefix=/www/server/php/56' '--with-config-file-path=/www/server/php/56/etc' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl=/usr/local/curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl=/usr/local/openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-opcache' '--enable-intl' Server API FPM/FastCGI Virtual Directory Support disabled Configuration File (php.ini) Path /www/server/php/56/etc Loaded Configuration File /www/server/php/56/etc/php.ini Scan this dir for additional .ini files (none) Additional .ini files parsed (none) PHP API 20131106 PHP Extension 20131226 Zend Extension 220131226 Zend Extension Build API220131226,NTS PHP Extension Build API20131226,NTS Debug Build no Thread Safety disabled Zend Signal Handling disabled Zend Memory Manager enabled Zend Multibyte Support provided by mbstring IPv6 Support enabled DTrace Support disabled Registered PHP Streams https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar, zip, smb, compress.zstd Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2 Registered Stream Filters zlib.*, convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk Zend logoThis program makes use of the Zend Scripting Language Engine: Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies Configuration bcmath BCMath support enabled Directive Local Value Master Value bcmath.scale 0 0 cgi-fcgi php-fpm active Directive Local Value Master Value cgi.discard_path 0 0 cgi.fix_pathinfo 1 1 cgi.force_redirect 1 1 cgi.nph 0 0 cgi.redirect_status_env no value no value cgi.rfc2616_headers 0 0 fastcgi.error_header no value no value fastcgi.logging 1 1 fpm.config no value no value Core PHP Version 5.6.40 Directive Local Value Master Value allow_url_fopen On On allow_url_include Off Off always_populate_raw_post_data 0 0 arg_separator.input & & arg_separator.output & & asp_tags Off Off auto_append_file no value no value auto_globals_jit On On auto_prepend_file no value no value browscap no value no value default_charset UTF-8 UTF-8 default_mimetype text/html text/html disable_classes no value no value disable_functions passthru,proc_open,putenv,exec,system,chroot,chgrp,chown,shell_exec,popen,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,proc_open,putenv,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv passthru,proc_open,putenv,exec,system,chroot,chgrp,chown,shell_exec,popen,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,proc_open,putenv,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv display_errors Off Off display_startup_errors Off Off doc_root no value no value docref_ext no value no value docref_root no value no value enable_dl Off Off enable_post_data_reading On On error_append_string no value no value error_log no value no value error_prepend_string no value no value error_reporting 32759 32759 exit_on_timeout Off Off expose_php Off Off extension_dir /www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226 /www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226 file_uploads On On highlight.comment #FF8000 #FF8000 highlight.default #0000BB #0000BB highlight.html #000000 #000000 highlight.keyword #007700 #007700 highlight.string #DD0000 #DD0000 html_errors On On ignore_repeated_errors Off Off ignore_repeated_source Off Off ignore_user_abort Off Off implicit_flush Off Off include_path .:/www/server/php/56/lib/php .:/www/server/php/56/lib/php input_encoding no value no value internal_encoding no value no value log_errors On On log_errors_max_len 1024 1024 mail.add_x_header On On mail.force_extra_parameters no value no value mail.log no value no value max_execution_time 300 300 max_file_uploads 20 20 max_input_nesting_level 64 64 max_input_time 60 60 max_input_vars 1000 1000 memory_limit 256M 256M open_basedir /www/wwwroot/szrengjing.com/:/tmp/ no value output_buffering 4096 4096 output_encoding no value no value output_handler no value no value post_max_size 100M 100M precision 14 14 realpath_cache_size 16K 16K realpath_cache_ttl 120 120 register_argc_argv Off Off report_memleaks On On report_zend_debug On On request_order GP GP sendmail_from no value no value sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i serialize_precision 17 17 short_open_tag On On SMTP localhost localhost smtp_port 25 25 sql.safe_mode Off Off sys_temp_dir no value no value track_errors Off Off unserialize_callback_func no value no value upload_max_filesize 100M 100M upload_tmp_dir no value no value user_dir no value no value user_ini.cache_ttl 300 300 user_ini.filename .user.ini .user.ini variables_order GPCS GPCS xmlrpc_error_number 0 0 xmlrpc_errors Off Off zend.detect_unicode On On zend.enable_gc On On zend.multibyte Off Off zend.script_encoding no value no value ctype ctype functions enabled curl cURL support enabled cURL Information 7.70.0 Age 6 Features AsynchDNS Yes CharConv No Debug No GSS-Negotiate No IDN No IPv6 Yes krb4 No Largefile Yes libz Yes NTLM Yes NTLMWB Yes SPNEGO No SSL Yes SSPI No TLS-SRP Yes Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps, pop3, pop3s, rtsp, smb, smbs, smtp, smtps, telnet, tftp Host x86_64-pc-linux-gnu SSL Version OpenSSL/1.0.2u ZLib Version 1.2.11 date date/time support enabled "Olson" Timezone Database Version 2016.10 Timezone Database internal Default timezone PRC Directive Local Value Master Value date.default_latitude 31.7667 31.7667 date.default_longitude 35.2333 35.2333 date.sunrise_zenith 90.583333 90.583333 date.sunset_zenith 90.583333 90.583333 date.timezone PRC PRC dom DOM/XML enabled DOM/XML API Version 20031129 libxml Version 2.9.7 HTML Support enabled XPath Support enabled XPointer Support enabled Schema Support enabled RelaxNG Support enabled ereg Regex Library Bundled library enabled event Event support enabled Sockets support enabled Debug support disabled Extra functionality support including HTTP, DNS, and RPC enabled OpenSSL support enabled Thread safety support disabled Extension version 3.0.8 libevent2 headers version 2.1.8-stable exif EXIF Support enabled EXIF Version 1.4 $Id: 1c8772f76be691b7b3f77ca31eb788a2abbcefe5 $ Supported EXIF Version 0220 Supported filetypes JPEG,TIFF Directive Local Value Master Value exif.decode_jis_intel JIS JIS exif.decode_jis_motorola JIS JIS exif.decode_unicode_intel UCS-2LE UCS-2LE exif.decode_unicode_motorola UCS-2BE UCS-2BE exif.encode_jis no value no value exif.encode_unicode ISO-8859-15 ISO-8859-15 fileinfo fileinfo support enabled version 1.0.5 libmagic 517 filter Input Validation and Filtering enabled Revision $Id: 5b79667bd9a68977a9b4f7505223a8e216e04908 $ Directive Local Value Master Value filter.default unsafe_raw unsafe_raw filter.default_flags no value no value ftp FTP support enabled gd GD Support enabled GD Version bundled (2.1.0 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.9.1 GIF Read Support enabled GIF Create Support enabled JPEG Support enabled libJPEG Version 6b PNG Support enabled libPNG Version 1.6.34 WBMP Support enabled XBM Support enabled Directive Local Value Master Value gd.jpeg_ignore_warning 0 0 gettext GetText Support enabled hash hash support enabled Hashing Engines md2 md4 md5 sha1 sha224 sha256 sha384 sha512 ripemd128 ripemd160 ripemd256 ripemd320 whirlpool tiger128,3 tiger160,3 tiger192,3 tiger128,4 tiger160,4 tiger192,4 snefru snefru256 gost gost-crypto adler32 crc32 crc32b fnv132 fnv1a32 fnv164 fnv1a64 joaat haval128,3 haval160,3 haval192,3 haval224,3 haval256,3 haval128,4 haval160,4 haval192,4 haval224,4 haval256,4 haval128,5 haval160,5 haval192,5 haval224,5 haval256,5 iconv iconv support enabled iconv implementation glibc iconv library version 2.28 Directive Local Value Master Value iconv.input_encoding no value no value iconv.internal_encoding no value no value iconv.output_encoding no value no value imagick imagick module enabled imagick module version 3.4.4 imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel Imagick compiled with ImageMagick version ImageMagick 7.1.0-16 Q16-HDRI x86_64 2021-11-21 https://imagemagick.org Imagick using ImageMagick library version ImageMagick 7.1.0-16 Q16-HDRI x86_64 2021-11-21 https://imagemagick.org ImageMagick copyright (C) 1999-2021 ImageMagick Studio LLC ImageMagick release date 2021-11-21 ImageMagick number of supported formats: 249 ImageMagick supported formats 3FR, 3G2, 3GP, A, AAI, AI, APNG, ART, ARW, ASHLAR, AVI, AVS, B, BGR, BGRA, BGRO, BMP, BMP2, BMP3, BRF, C, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUBE, CUR, CUT, DATA, DCM, DCR, DCRAW, DCX, DDS, DFONT, DNG, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FARBFELD, FAX, FF, FILE, FITS, FL32, FLV, FRACTAL, FTP, FTS, G, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, JNG, JNX, JPE, JPEG, JPG, JPS, JSON, K, K25, KDC, LABEL, M, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, O, ORA, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PHM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PS, PS2, PS3, PSB, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGB565, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCREENSHOT, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TM2, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMV, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, Y, YAML, YCbCr, YCbCrA, YUV Directive Local Value Master Value imagick.locale_fix 0 0 imagick.progress_monitor 0 0 imagick.skip_version_check 0 0 intl Internationalization support enabled version 1.1.0 ICU version 60.3 ICU Data version 60.3 Directive Local Value Master Value intl.default_locale no value no value intl.error_level 0 0 intl.use_exceptions 0 0 json json support enabled json version 1.2.1 libsmbclient Version 1.0.6 libxml libXML support active libXML Compiled Version 2.9.7 libXML Loaded Version 20907 libXML streams enabled mbstring Multibyte Support enabled Multibyte string engine libmbfl HTTP input encoding translation disabled libmbfl version 1.3.2 mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1. Multibyte (japanese) regex support enabled Multibyte regex (oniguruma) backtrack check On Multibyte regex (oniguruma) version 5.9.5 Directive Local Value Master Value mbstring.detect_order no value no value mbstring.encoding_translation Off Off mbstring.func_overload 0 0 mbstring.http_input no value no value mbstring.http_output no value no value mbstring.http_output_conv_mimetypes ^(text/|application/xhtml\+xml) ^(text/|application/xhtml\+xml) mbstring.internal_encoding no value no value mbstring.language neutral neutral mbstring.strict_detection Off Off mbstring.substitute_character no value no value mcrypt mcrypt support enabled mcrypt_filter support enabled Version 2.5.8 Api No 20021217 Supported ciphers cast-128 gost rijndael-128 twofish arcfour cast-256 loki97 rijndael-192 saferplus wake blowfish-compat des rijndael-256 serpent xtea blowfish enigma rc2 tripledes Supported modes cbc cfb ctr ecb ncfb nofb ofb stream Directive Local Value Master Value mcrypt.algorithms_dir no value no value mcrypt.modes_dir no value no value memcached memcached support enabled Version 2.2.0 libmemcached version 1.0.18 SASL support yes Session support yes igbinary support no json support no msgpack support no Directive Local Value Master Value memcached.compression_factor 1.3 1.3 memcached.compression_threshold 2000 2000 memcached.compression_type fastlz fastlz memcached.serializer php php memcached.sess_binary 0 0 memcached.sess_connect_timeout 1000 1000 memcached.sess_consistent_hash 0 0 memcached.sess_lock_expire 0 0 memcached.sess_lock_max_wait 0 0 memcached.sess_lock_wait 150000 150000 memcached.sess_locking 1 1 memcached.sess_number_of_replicas 0 0 memcached.sess_prefix memc.sess.key. memc.sess.key. memcached.sess_randomize_replica_read 0 0 memcached.sess_remove_failed 0 0 memcached.sess_sasl_password no value no value memcached.sess_sasl_username no value no value memcached.store_retry_count 2 2 memcached.use_sasl 0 0 mhash MHASH support Enabled MHASH API Version Emulated Support mysql MySQL Support enabled Active Persistent Links 0 Active Links 0 Client API version mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $ Directive Local Value Master Value mysql.allow_local_infile On On mysql.allow_persistent On On mysql.connect_timeout 60 60 mysql.default_host no value no value mysql.default_password no value no value mysql.default_port no value no value mysql.default_socket no value no value mysql.default_user no value no value mysql.max_links Unlimited Unlimited mysql.max_persistent Unlimited Unlimited mysql.trace_mode Off Off mysqli MysqlI Support enabled Client API library version mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $ Active Persistent Links 0 Inactive Persistent Links 0 Active Links 0 Directive Local Value Master Value mysqli.allow_local_infile On On mysqli.allow_persistent On On mysqli.default_host no value no value mysqli.default_port 3306 3306 mysqli.default_pw no value no value mysqli.default_socket no value no value mysqli.default_user no value no value mysqli.max_links Unlimited Unlimited mysqli.max_persistent Unlimited Unlimited mysqli.reconnect Off Off mysqli.rollback_on_cached_plink Off Off mysqlnd mysqlnd enabled Version mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $ Compression supported core SSL supported extended SSL supported Command buffer size 4096 Read buffer size 32768 Read timeout 31536000 Collecting statistics Yes Collecting memory statistics No Tracing n/a Loaded plugins mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password API Extensions pdo_mysql,mysqli,mysql mysqlnd statistics bytes_sent 90861536 bytes_received 394494535 packets_sent 1356160 packets_received 6262207 protocol_overhead_in 25048828 protocol_overhead_out 5424640 bytes_received_ok_packet 0 bytes_received_eof_packet 0 bytes_received_rset_header_packet 5709357 bytes_received_rset_field_meta_packet 0 bytes_received_rset_row_packet 3386087 bytes_received_prepare_response_packet 153977064 bytes_received_change_user_packet 227294569 packets_sent_command 665079 packets_received_ok 0 packets_received_eof 0 packets_received_rset_header 634373 packets_received_rset_field_meta 0 packets_received_rset_row 645578 packets_received_prepare_response 2273832 packets_received_change_user 2682422 result_set_queries 627873 non_result_set_queries 17703 no_index_used 47526 bad_index_used 0 slow_queries 0 buffered_sets 627873 unbuffered_sets 0 ps_buffered_sets 0 ps_unbuffered_sets 0 flushed_normal_sets 0 flushed_ps_sets 0 ps_prepared_never_executed 0 ps_prepared_once_executed 0 rows_fetched_from_server_normal 2054549 rows_fetched_from_server_ps 0 rows_buffered_from_client_normal 2054549 rows_buffered_from_client_ps 0 rows_fetched_from_client_normal_buffered 2053367 rows_fetched_from_client_normal_unbuffered 0 rows_fetched_from_client_ps_buffered 0 rows_fetched_from_client_ps_unbuffered 0 rows_fetched_from_client_ps_cursor 0
11-10
[root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# find / -name "mysqld" -type f 2>/dev/null /export/server/mysql/bin/mysqld /export/server/mysql/mysql-5.7.43-linux-glibc2.12-x86_64/bin/mysqld [root@master ~]# sudo /export/server/mysql/bin/mysqld --user=mysql --skip-grant-tables --skip-networking & [1] 26278 [root@master ~]# 2025-12-30T01:49:57.352070Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2025-12-30T01:49:57.352139Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled 2025-12-30T01:49:57.352175Z 0 [Note] /export/server/mysql/bin/mysqld (mysqld 5.7.43) starting as process 26279 ... 2025-12-30T01:49:57.355919Z 0 [Note] InnoDB: PUNCH HOLE support available 2025-12-30T01:49:57.355935Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2025-12-30T01:49:57.355938Z 0 [Note] InnoDB: Uses event mutexes 2025-12-30T01:49:57.355939Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier 2025-12-30T01:49:57.355941Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13 2025-12-30T01:49:57.355943Z 0 [Note] InnoDB: Using Linux native AIO 2025-12-30T01:49:57.356115Z 0 [Note] InnoDB: Number of pools: 1 2025-12-30T01:49:57.356206Z 0 [Note] InnoDB: Using CPU crc32 instructions 2025-12-30T01:49:57.357201Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2025-12-30T01:49:57.362384Z 0 [Note] InnoDB: Completed initialization of buffer pool 2025-12-30T01:49:57.364443Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2025-12-30T01:49:57.376880Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2025-12-30T01:49:57.382570Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2025-12-30T01:49:57.382582Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2025-12-30T01:49:57.382602Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2025-12-30T01:49:57.397458Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2025-12-30T01:49:57.397955Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2025-12-30T01:49:57.397964Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2025-12-30T01:49:57.398146Z 0 [Note] InnoDB: Waiting for purge to start 2025-12-30T01:49:57.449115Z 0 [Note] InnoDB: 5.7.43 started; log sequence number 2767312 2025-12-30T01:49:57.449323Z 0 [Note] Plugin 'FEDERATED' is disabled. 2025-12-30T01:49:57.449374Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool 2025-12-30T01:49:57.450649Z 0 [Note] InnoDB: Buffer pool(s) load completed at 251230 9:49:57 2025-12-30T01:49:57.453043Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 2025-12-30T01:49:57.453065Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. 2025-12-30T01:49:57.453069Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2025-12-30T01:49:57.453071Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2025-12-30T01:49:57.457101Z 0 [Warning] CA certificate ca.pem is self signed. 2025-12-30T01:49:57.457136Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 2025-12-30T01:49:57.483684Z 0 [Note] /export/server/mysql/bin/mysqld: ready for connections. Version: '5.7.43' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Server (GPL) /export/server/mysql/bin/mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# [root@master ~]# /export/server/mysql/bin/mysql -u root -S /var/lib/mysql/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.43 MySQL Community Server (GPL) Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> USE mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE user SET authentication_string = PASSWORD('123456') WHERE User = 'root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> EXIT; Bye [root@master ~]# mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) [root@master ~]# mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) [root@master ~]# /export/server/mysql/bin/mysql -u root -S /var/lib/mysql/mysql.sock 2025-12-30T01:51:35.871938Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@master ~]# /export/server/mysql/bin/mysql -u root -S /var/lib/mysql/mysql.sock 2025-12-30T01:51:39.642261Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@master ~]# 什么情况
12-31
<think>嗯,用户想了解如何设置或修改MySQL的secure_file_priv参数来控制文件加载权限,特别是设置为空时是否允许LOAD_FILE权限。首先,我需要回顾一下之前提供的引用内容,确保信息准确。根据引用[1]和[2],secure_file_priv参数确实用来限制导入导出操作的位置。当设置为NULL时,MySQL不允许导入导出;设置为目录时,限制在该目录;如果为空,则不限制,但这样不安全。用户提到设置为空允许LOAD_FILE权限,但根据引用[2],设置为空确实允许在所有目录操作,所以需要明确这一点。接下来,用户的问题是如何设置secure_file_priv为空。根据引用[2],这个参数不能通过SETGLOBAL动态修改,必须修改配置文件并重启MySQL服务。引用[3]中的例子也说明需要重启服务才能生效,比如关闭phpstudy的服务再启动。因此,步骤应该包括编辑my.cnf或my.ini文件,添加secure_file_priv="",然后重启服务。同时,用户可能混淆了FILE权限和secure_file_priv的关系。即使有FILE权限,secure_file_priv的设置也会影响LOAD DATA和SELECTINTOOUTFILE的操作路径。需要强调这两个设置的结合使用。安全方面,设置为空虽然方便,但风险较高,容易被利用。应该提醒用户权衡便利与安全,建议仅在可信环境中使用,并考虑其他安全措施,如限制MySQL进程用户的文件访问权限。另外,用户之前的问题中提到了LOAD_FILE权限的开启,这里需要区分FILE权限和secure_file_priv参数的不同作用。FILE权限是用户权限层面的控制,而secure_file_priv是系统层面的路径限制。两者需同时满足才能执行相关操作。 最后,验证步骤很重要,用户需要知道如何检查当前secure_file_priv的值,使用SHOWVARIABLES命令,并测试是否能成功执行LOAD_FILE或导出操作。可能遇到的问题包括配置文件位置错误、权限不足或服务未正确重启,需要给出常见问题解决方法,比如检查配置文件路径、确认重启服务等。 生成的相关问题需要围绕secure_file_priv的影响、与其他权限的交互、安全配置以及错误处理等方面,帮助用户进一步理解相关设置。</think>### 如何设置 MySQL 的 `secure_file_priv` 参数以控制文件加载权限 #### 一、`secure_file_priv` 参数的作用 1. **功能定义** `secure_file_priv` 是 MySQL 的安全参数,用于限制以下操作的执行路径: - `LOAD DATA INFILE` / `LOAD DATA LOCAL INFILE` - `SELECT ... INTO OUTFILE` - `LOAD_FILE()` 函数 若参数值为 `NULL`,表示禁止所有导入导出操作;若为目录路径,则限制操作仅能在该目录下执行;若为空(`""`),则不限制路径[^1][^2]。 2. **与 `LOAD_FILE` 权限的关系** - 即使用户拥有 `FILE` 权限,若 `secure_file_priv` 设置为 `NULL`,也无法执行文件操作。 - 若设置为空(`""`),则允许用户在任意路径执行文件操作[^1][^2]。 --- #### 二、设置 `secure_file_priv` 为空的操作步骤 1. **修改配置文件** - 找到 MySQL 的配置文件(通常为 `my.cnf` 或 `my.ini`),在 `[mysqld]` 部分添加: ```ini [mysqld] secure_file_priv = "" ``` - **注意**:此参数无法通过 `SET GLOBAL` 动态修改,必须重启 MySQL 服务生效[^2][^3]。 2. **重启 MySQL 服务** ```bash # 示例(根据系统选择命令) systemctl restart mysql # Linux systemd service mysql restart # SysVinit /etc/init.d/mysql restart # 其他环境 ``` 3. **验证设置** 执行 SQL 命令检查参数值: ```sql SHOW VARIABLES LIKE 'secure_file_priv'; ``` 若输出为 `Value: `(空值),则配置成功[^2][^3]。 --- #### 三、安全风险与缓解措施 1. **潜在风险** - 允许任意路径操作可能导致敏感文件泄露或被篡改(例如通过 `LOAD_FILE()` 读取系统文件)。 - 攻击者可能利用此功能上传恶意文件[^4]。 2. **安全建议** - **仅在可信环境设置空值**:避免在生产环境中使用 `secure_file_priv = ""`。 - **限制目录**:推荐设置为特定目录(如 `/var/mysql_import`),并确保目录权限仅允许 MySQL 用户访问。 - **结合权限控制**:仅对必要用户授予 `FILE` 权限[^1][^2]。 --- #### 四、常见问题解决 1. **配置未生效** - 检查配置文件路径是否正确(不同安装方式可能路径不同)。 - 确认修改的是 `[mysqld]` 部分而非其他段落。 - 某些集成环境(如 phpStudy)需通过界面重启服务[^3]。 2. **权限冲突** - 若用户无 `FILE` 权限,即使 `secure_file_priv` 为空也无法操作文件。需执行: ```sql GRANT FILE ON *.* TO 'user'@'host'; FLUSH PRIVILEGES; ``` --- #### 五、数学表达示例(与参数无关,仅演示格式) 若需分析文件访问的路径限制,可定义允许的操作路径集合为: $$ S = \{ x \mid x \in \text{secure_file_priv允许的目录} \} $$ 当 `secure_file_priv = ""` 时,$S$ 覆盖所有合法路径。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值