macOS mysql,如何解決命令行導入txt等文件出現(xiàn)的secure-file-priv導入文件權(quán)限問題

學習mysql必不可少的就是學會用命令行對數(shù)據(jù)庫進行操作赦肋,在我今天學習如何使用命令行來進行txt文件導入數(shù)據(jù)操作時块攒,出現(xiàn)了以下問題

ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

后來我查閱資料,大部分都是windows系統(tǒng)下的解決方式佃乘,以下為介紹囱井,為mac系統(tǒng)解決該問題打下基礎(chǔ)

Windows系統(tǒng)解決方式

在mysql系統(tǒng)中查看secure-file-priv ,登陸數(shù)據(jù)庫趣避,輸入如下代碼

SHOW VARIABLES LIKE "secure_file_priv";
image.png

發(fā)現(xiàn)secure_file_priv的值為null庞呕,也就是數(shù)據(jù)庫認為的安全文件為空,認為什么都不安全,這就是為什么無法導入導出外部數(shù)據(jù)的原因住练。

解決步驟
image.png

image.png

這就是Windows系統(tǒng)上的解決方式地啰,mac系統(tǒng)也可以照葫蘆畫瓢,可惜mac系統(tǒng)默認沒有my.cnf文件讲逛,我們得自己來

macOS系統(tǒng)下解決方式

  • 1亏吝、輸入:cd /etc
  • 2、輸入:sudo vim my.cnf
  • 3盏混、輸入你電腦的登錄密碼


    image.png
  • 4蔚鸥、在vim編輯器模式下,輸入如下代碼
# Example MySQL config file for medium systems.
  #
  # This is for a system with little memory (32M - 64M) where MySQL plays
  # an important part, or systems up to 128M where MySQL is used together with
  # other programs (such as a web server)
  #
  # MySQL programs look for option files in a set of
  # locations which depend on the deployment platform.
  # You can copy this option file to one of those
  # locations. For information about these locations, see:
  # http://dev.mysql.com/doc/mysql/en/option-files.html
  #
  # In this file, you can use all long options that a program supports.
  # If you want to know which options a program supports, run the program
  # with the "--help" option.
  # The following options will be passed to all MySQL clients
  [client]
  default-character-set=utf8
  #password   = your_password
  port        = 3306
  socket      = /tmp/mysql.sock
  # Here follows entries for some specific programs
  # The MySQL server
  [mysqld]
  character-set-server=utf8
  init_connect='SET NAMES utf8
  port        = 3306
  socket      = /tmp/mysql.sock
  skip-external-locking
  key_buffer_size = 16M
  max_allowed_packet = 1M
  table_open_cache = 64
  sort_buffer_size = 512K
  net_buffer_length = 8K
  read_buffer_size = 256K
  read_rnd_buffer_size = 512K
  myisam_sort_buffer_size = 8M
  character-set-server=utf8
  init_connect='SET NAMES utf8'
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

  # Replication Master Server (default)
  # binary logging is required for replication
  log-bin=mysql-bin

    # binary logging format - mixed recommended
    binlog_format=mixed
     # required unique id between 1 and 2^32 - 1
      # defaults to 1 if master-host is not set
      # but will not function as a master if omitted
      server-id   = 1

    # Replication Slave (comment out master section to use this)
    #
    # To configure this host as a replication slave, you can choose between
    # two methods :
    #
    # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
    #    the syntax is:
    #
    #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
    #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
    #
    #    where you replace <host>, <user>, <password> by quoted strings and
    #    <port> by the master's port number (3306 by default).
    #
    #    Example:
    #
    #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
    #    MASTER_USER='joe', MASTER_PASSWORD='secret';
    #
    # OR
    #
    # 2) Set the variables below. However, in case you choose this method, then
    #    start replication for the first time (even unsuccessfully, for example
    #    if you mistyped the password in master-password and the slave fails to
    #    connect), the slave will create a master.info file, and any later
    #    change in this file to the variables' values below will be ignored and
    #    overridden by the content of the master.info file, unless you shutdown
    #    the slave server, delete master.info and restart the slaver server.
    #    For that reason, you may want to leave the lines below untouched
    #    (commented) and instead use CHANGE MASTER TO (see above)
    #
    # required unique id between 2 and 2^32 - 1
    # (and different from the master)
    # defaults to 2 if master-host is set
    # but will not function as a slave if omitted
    #server-id       = 2
    #
    # The replication master for this slave - required
    #master-host     =   <hostname>
    #
    # The username the slave will use for authentication when connecting
    # to the master - required
    #master-user     =   <username>
    #
    # The password the slave will authenticate with when connecting to
    # the master - required
    #master-password =   <password>
    #
    # The port the master is listening on.
    # optional - defaults to 3306
    #master-port     =  <port>
    #
    # binary logging - not required for slaves, but recommended
    #log-bin=mysql-bin

      # Uncomment the following if you are using InnoDB tables
      #innodb_data_home_dir = /usr/local/mysql/data
      #innodb_data_file_path = ibdata1:10M:autoextend
      #innodb_log_group_home_dir = /usr/local/mysql/data
      # You can set .._buffer_pool_size up to 50 - 80 %
      # of RAM but beware of setting memory usage too high
      #innodb_buffer_pool_size = 16M
      #innodb_additional_mem_pool_size = 2M
      # Set .._log_file_size to 25 % of buffer pool size
      #innodb_log_file_size = 5M
      #innodb_log_buffer_size = 8M
      #innodb_flush_log_at_trx_commit = 1
      #innodb_lock_wait_timeout = 50

        [mysqldump]
        quick
        max_allowed_packet = 16M

          [mysql]
          no-auto-rehash
          # Remove the next comment character if you are not familiar with SQL
          #safe-updates
          default-character-set=utf8

        [myisamchk]
        key_buffer_size = 20M
        sort_buffer_size = 20M
        read_buffer = 2M
        write_buffer = 2M

          [mysqlhotcopy]
          interactive-timeout

secure_file_priv=''
[mysqld]
local-infile=1
[mysql]
local-infile=1

  • 5许赃、esc : wq 保存即可
  • 6止喷、重啟mysql服務(wù)器

如上述操作不可行 可試試下面方法 mysql版本 8.0.21 macOS big sur

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市技羔,隨后出現(xiàn)的幾起案子僵闯,更是在濱河造成了極大的恐慌,老刑警劉巖藤滥,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件鳖粟,死亡現(xiàn)場離奇詭異,居然都是意外死亡拙绊,警方通過查閱死者的電腦和手機向图,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來标沪,“玉大人榄攀,你說我怎么就攤上這事〗鹁洌” “怎么了檩赢?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長违寞。 經(jīng)常有香客問我贞瞒,道長,這世上最難降的妖魔是什么趁曼? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任军浆,我火速辦了婚禮,結(jié)果婚禮上挡闰,老公的妹妹穿的比我還像新娘乒融。我一直安慰自己掰盘,他們只是感情好,可當我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布赞季。 她就那樣靜靜地躺著愧捕,像睡著了一般。 火紅的嫁衣襯著肌膚如雪碟摆。 梳的紋絲不亂的頭發(fā)上晃财,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天叨橱,我揣著相機與錄音典蜕,去河邊找鬼。 笑死罗洗,一個胖子當著我的面吹牛愉舔,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播伙菜,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼轩缤,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了贩绕?” 一聲冷哼從身側(cè)響起火的,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎淑倾,沒想到半個月后馏鹤,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡娇哆,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年湃累,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片碍讨。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡治力,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出勃黍,到底是詐尸還是另有隱情宵统,我是刑警寧澤,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布覆获,位于F島的核電站马澈,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏锻梳。R本人自食惡果不足惜箭券,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望疑枯。 院中可真熱鬧辩块,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至豆村,卻和暖如春液兽,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背掌动。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工四啰, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人粗恢。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓柑晒,卻偏偏與公主長得像,于是被迫代替她去往敵國和親眷射。 傳聞我的和親對象是個殘疾皇子匙赞,可洞房花燭夜當晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容