root@bogon:/data/mysql# kill `cat ./mysql.pid`
其中,mysql.pid 指的是 MySQL 數據目錄下的 pid 文件,它記錄了 MySQL 服務的進程號。mysql
zj@bogon:/data/mysql$ sudo /usr/local/mysql/bin/mysqld --skip-grant-tables --user=root &
--skip-grant-tables 選項意思是啓動 MySQL 服務時跳過權限表認證。啓動後,鏈接到 MySQL 的 root 將不須要口令。sql
zj@bogon:/usr/local/mysql/bin$ mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18-log Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 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 [(none)]> set password = password('123456'); ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement MySQL [(none)]> use mysql Database changed MySQL [mysql]> update user set authentication_string=password('123456') where user="root" and host="localhost"; Query OK, 1 row affected, 1 warning (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 1 MySQL [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec) MySQL [mysql]> exit; Bye **************************************************************** zj@bogon:/usr/local/mysql/bin$ mysql -uroot -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.18-log Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 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 [(none)]>
因爲使用了 --skip-grant-tables 選項啓動,使用 「set password」 命令更改密碼失敗,直接更新 user 表的 authentication_string(測試版本爲5.7.18,有的版本密碼字段是 ‘password’) 字段後,更改密碼成功。刷新權限表,使權限認證從新生效。從新用 root 登陸時,就可使用剛剛修改後的口令了。shell
有的時候可能會遇到 myisam 表損壞的狀況。一張損壞的表的症狀一般是查詢意外中斷,而且能看到下述錯誤:數據庫
'table_name.frm' 被鎖定不能更改安全
不能找到文件 'tbl_name.MYYI' (errcode:nnn)服務器
文件意外結束socket
記錄文件被毀壞tcp
從表處理器獲得錯誤 nnn。工具
一般有如下兩種解決方法:測試
使用 MySQL 自帶的 myisamchk 工具進行修復:
shell> myisamchk -r tablename
其中 -r 參數的含義是 recover,上面的方法幾乎能解決全部問題,若是不行,則使用命令:
shell> mysiamchk -o tablename
其中 -o 參數的含義是 --safe-recover,能夠進行更安全的修復。
使用 MySQL 的 check table 和 repair table 命令一塊兒進行修復,check table 用來檢查表是否有損壞;repair table 用來對壞表進行修復。
系統上線後,隨着數據量的不斷增長,會發現數據目錄下的可用空間愈來愈小,從而給應用形成了安全隱患。
對於 myisam 存儲引擎的表,在建表時能夠用以下選項分別制定數據目錄和索引目錄存儲到不一樣的磁盤空間,而默認會同時放在數據目錄下:
data directory = 'absolute path to directory' index directory = 'absolute path to directory'
若是表已經建立,只能先停機或者將表鎖定,防止表的更改,而後將表的數據文件和索引文件 mv 到磁盤充足的分區上,而後在原文件處建立符號連接便可。
由於數據文件和索引文件是存放在一塊兒的,因此沒法將它們分離。當磁盤空間出現不足時,能夠增長一個新的數據文件,這個文件放在充足空間的磁盤上。
具體實現方法是在參數 innodb_data_file_path 中增長此文件,路徑寫爲新磁盤的絕對路徑。
例如,若是 /home 下空間不足,但願在 /home1 下新增長一個可自動擴充數據的文件,那麼參數能夠這麼寫:
innodb_data_file_path = /home/ibdata1:2000M;/home1/ibdata2:2000M:autoextend
參數修改後,必須重啓數據庫才能夠生效。
在客戶端執行 show processlist 命令,有時會出現不少進程,相似於:
unauthenticated user | 192.168.10.10:55644 | null | connect | null | login | null
這些進程會累計的愈來愈多,而且不會消失,應用沒法正常相應,致使系統癱瘓。
MySQL 在默認狀況下對於遠程鏈接過來的 IP 地址會進行域名的逆向解析,若是系統的 hosts 文件中沒有與之對應的域名,MySQL 就會將此鏈接認爲是無效用戶,因此下進程中出現 unauthenticated user 並致使進程阻塞。
解決的方法很簡單,在啓動時加上 --skip-name-resolve 選項,則 MySQL 就能夠跳過域名解析過程,避免上述問題。
在 MySQL 服務器本機上鍊接數據庫時,常常會出現 mysql.sock 不存在,致使沒法鏈接的問題。這是由於若是指定 localhost 做爲一個主機名,則 mysqladmin 默認使用 Unix 套接字文件鏈接,而不是 tcp/ip。而這個套接字文件(通常命名爲 mysql.sock)常常會由於各類緣由而被刪除。經過 --protocol=TCP|SOCKET|PIPE|MEMORY 選項,用戶能夠顯式地指定鏈接協議,下面演示使用了 Unix 套接字失敗後使用 tcp 協議鏈接成功的例子。
zj@bogon:~$ mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
zj@bogon:~$ mysql --protocol=TCP