vim 編輯模式下可以顯示行數“sudo vi /etc/vim/vimrc”在開啟的檔案中加入“set nu”儲存後退出。
利用:”vi .bash_history“查看之前輸入過的命令
編譯操作資料庫的程式test.c時 輸入”./test“提示錯誤:
Connection error 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
此時更改mysql下進行資料庫連接時的mysql_real_connect(&mysql, "localhost", "localhost", "", "myclink", 0, NULL, 0)其中的第一個localhost換為”127.0.0.1“,記得輸入密碼”111“
編譯操作資料庫的程式test.c時 輸入”./test”提示錯誤:./test: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory,此時用命令”export“查看環境變數,發現沒有mysql的lib的路徑,此時輸入”vi .bashrc“,在末尾行輸入”export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib“將該路徑動態添加到環境變數(如果直接在export中間添加,則屬於session對話,此時對環境變數的改變屬於臨時改變,www.bkjia.com在該對話結束後,環境變數會恢複為以前的狀態,而.bashrc在每次編譯時間會動態執行一次,故可以一次寫入,每次調用.bashrc將環境變數添加進去)
輸入 gcc -o test $(./mysql_config --cflags) test.c $(./mysql_config –libs)
編譯時間,提示錯誤資訊:
bash: ./mysql_config:
No such file or directorybash: ./mysql_config:
No such file or directorytest.c: In function ‘main’:test.c:36:50:
warning: incompatible implicit declaration of built-in function ‘strlen’/tmp/ccfnwW6I.o:
In function `main':test.c:(.text+0xa9): undefined reference to `mysql_init'test.c:(.text+0xed): undefined reference to `mysql_real_connect'test.c:(.text+0xfd):
undefined reference to `mysql_error'test.c:(.text+0x14f):
undefined reference to `mysql_real_query'test.c:(.text+0x166):
undefined reference to `mysql_error'test.c:(.text+0x1a2):
undefined reference to `mysql_close'collect2:
ld returned 1 exit status,
此時將mysql_config複製到程式當前路徑下並命名為mysql_config,輸入
”cp ./workspace/insert/mysql_config ./mysql_config“
此時”ls“看到目前的目錄下複製了一個mysql_config檔案,
輸入 gcc -o test $(./mysql_config --cflags) test.c $(./mysql_config –libs)
再輸入”gcc -o test $(./mysql_config --cflags) test.c $(./mysql_config –libs)”
此時在該目錄下產生可執行檔test