mysql腳本mysql_safe解釋、mysql.sock文件、mysql_install_db

一、首先解釋下,啓動mysql時爲什麼會調用mysql_safe腳原本啓動mysqlmysql

[root@localhost ~]# /etc/init.d/mysqld start
正在啓動 mysqld:                                          [肯定]
[root@localhost ~]# ps -ef | grep mysql
root     13052     1  0 11:41 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql    13283 13052 20 11:41 pts/0    00:00:03 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root     14814  2418  0 11:41 pts/0    00:00:00 grep mysql
[root@localhost ~]# 

mysql_safe:mysql服務啓動腳本sql

 1 [root@localhost ~]# cat /etc/init.d/mysqld 
 2 #!/bin/sh
 3 #
 4 # mysqld    This shell script takes care of starting and stopping
 5 #        the MySQL subsystem (mysqld).
 6 exec="/usr/bin/mysqld_safe"
 7 prog="mysqld"
 8 $exec   --datadir="$datadir" --socket="$socketfile" \
 9         --pid-file="$mypidfile" \
10         --basedir=/usr --user=mysql >/dev/null 2>&1 &
11 safe_pid=$!

解釋:由於/etc/init.d/mysqld是一個shell啓動腳本,啓動後最終會調用mysqld_safe腳本,最後請用mysqld腳本啓動mysql,以下:/etc/init.d/mysqld腳本中調用mysqld_safe的程序。shell

二、mysql.sock文件數據庫

  mysql.sock文件是用來服務器與本地客戶端進行通訊的Unix套接字文件,它比tcp快。一般遇到這個問題的緣由就是你的mysql server沒運行起來。服務器

[root@localhost ~]# mysql -p
Enter password: ERROR
2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [root@localhost ~]# service mysqld start 正在啓動 mysqld: [肯定] [root@localhost ~]# mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.29 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>

 mysql.sock文件所處位置:通常爲:socket

[root@localhost ~]# cat /etc/my.cnf
[mysqld]
socket=/var/lib/mysql/mysql.sock

Mysql有兩種鏈接方式: 
(1)TCP/IP 
(2)sockettcp

 對mysql.sock來講,其做用是程序與mysqlserver處於同一臺機器,發起本地鏈接時可用。 不須要自定義host。所以,即便你改變mysql的外部port也是同樣可能正常鏈接。 由於你在my.ini中或my.cnf中改變端口後,mysql.sock是隨每一次 mysql server啓動生成的。已經根據你在更改完my.cnf後重啓mysql時從新生成了一次,信息已跟着變動。 那麼對於外部鏈接,必須是要變動host才能鏈接的。sqlserver

 

三、mysql_install_db:初始化MYSQL數據庫目錄.spa

[root@localhost ~]# mysql_install_db --datadir=/var/lib/mysql/
Installing MySQL system tables...2016-03-15 11:00:50 0 [Warning] TIMESTAMP wi
相關文章
相關標籤/搜索