0 查看mysql進程 ps -ef|grep mysql
[root@localhost mysql]# ps -ef|grep mysql root 10626 7899 0 09:14 pts/0 00:00:00 mysql -u zt_dev -p root 22002 10757 0 14:32 pts/1 00:00:00 grep --color=auto mysql mysql 28782 1 0 3月04 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr mysql 28997 28782 3 3月04 ? 13:15:11 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
查看文件安裝路徑 whereis mysql
[root@localhost mysql]# whereis mysql mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
查詢運行文件所在路徑 which mysql
[root@localhost mysql]# which mysql
/usr/bin/mysql (運行文件是一堆亂碼 看不懂 不要進去看了)
1 登錄mysql后執行命令 show variables like '%dir%';
mysql> show variables like '%dir%'; +-----------------------------------------+----------------------------+ | Variable_name | Value | +-----------------------------------------+----------------------------+ | basedir | /usr/ | | binlog_direct_non_transactional_updates | OFF | | character_sets_dir | /usr/share/mysql/charsets/ | | datadir | /var/lib/mysql/ | | ignore_db_dirs | | | innodb_data_home_dir | | | innodb_log_group_home_dir | ./ | | innodb_max_dirty_pages_pct | 75 | | innodb_max_dirty_pages_pct_lwm | 0 | | innodb_tmpdir | | | innodb_undo_directory | . | | lc_messages_dir | /usr/share/mysql/ | | plugin_dir | /usr/lib64/mysql/plugin/ | | slave_load_tmpdir | /tmp | | tmpdir | /tmp | +-----------------------------------------+----------------------------+ 15 rows in set (0.00 sec)
2 數據庫目錄:/var/lib/mysql/
配置文件my.cnf中 會 有一條配置 datadir=/var/lib/mysql 指定數據庫目錄位置
linux 和 navicate 顯示的數據庫目錄一樣 如下

3 配置文件 /etc/my.cnf
[root@localhost mysql]# cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] character_set_server = utf8 collation-server=utf8_general_ci # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql mysql數據存儲在這里 socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Recommended in standard MySQL setup sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid # Maximum length for GROUP_CONCAT group_concat_max_len = -1
4 mysql.sock的作用
對mysql.sock來說,其作用是程序與mysqlserver處於同一台機器,發起本地連接時可用
例如你無須定義連接host的具體IP地址,只要為空或localhost就可以。
在此種情況下,即使你改變mysql的外部port也是一樣可能正常連接。
因為你在my.ini中或my.cnf中改變端口后,mysql.sock是隨每一次 mysql server啟動生成的。已經根據你在更改完my.cnf后重啟mysql時重新生成了一次,信息已跟着變更。
那么對於外部連接,必須是要變更port才能連接的。
linux下安裝mysql連接的時候經常回提示說找不到mysql.sock文件,解決辦法很簡單:
如果是新安裝的mysql,提示找不到文件,就搜索下,指定正確的位置。
如果mysql.sock文件誤刪的話,就需要重啟mysql服務,如果重啟成功的話會在datadir目錄下面生成mysql.sock 到時候指定即可。
5 pid文件 /var/run/mysqld/mysqld.pid
當mysql實例啟動時,會將自己的進程id寫入一個文件中,
該文件即為pid文件。
6 錯誤日志log-error文件 /var/log/mysqld.log
[root@localhost mysql]# tail -f /var/log/mysqld.log Version: '5.6.44' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL) 2020-03-04 10:26:03 28997 [Warning] IP address 'xxx.xxx.x.xxx' could not be resolved: Name or service not known 2020-03-04 10:26:45 28997 [Warning] IP address 'xxx.xxx.x.xx' could not be resolved: Name or service not known
