MySQL入门——Linux下安装后的配置文件

2022-10-13,,,,

mysql入门——linux下安装后的配置文件

摘要:本文主要了解了在linux环境下安装mysql后的配置文件的位置,以及如何创建配置文件。

查看配置文件的加载顺序

找到mysqld的路径

通过which命令查询mysqld的路径:

1 [root@localhost ~]# which mysqld
2 /usr/sbin/mysqld
3 [root@localhost ~]# 

查询帮助文件里的配置文件的加载顺序

通过帮助文件找到配置文件的加载路径:

1 [root@localhost ~]# /usr/sbin/mysqld --help --verbose | grep -a 1 'default options'
2 2019-11-18 19:13:20 0 [note] /usr/sbin/mysqld (mysqld 5.6.45) starting as process 1802 ...
3 2019-11-18 19:13:20 1802 [note] plugin 'federated' is disabled.
4 default options are read from the following files in the given order:
5 /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 
6 2019-11-18 19:13:20 1802 [note] binlog end
7 2019-11-18 19:13:20 1802 [note] shutting down plugin 'myisam'
8 2019-11-18 19:13:20 1802 [note] shutting down plugin 'csv'
9 [root@localhost ~]# 

这个帮助文件显示的内容说明在加载配置文件时,首先读取的是 /etc/my.cnf 文件,如果文件不存在则继续读取 /etc/mysql/my.cnf 文件,如若还不存在便会去读 /usr/etc/my.cnf 文件,如果之前的文件都不存在,则最后尝试读取 ~/.my.cnf 文件。

生成配置文件

查看配置文件

使用whereis命令查询mysql的配置文件:

1 [root@localhost ~]# whereis my.cnf
2 my: /etc/my.cnf
3 [root@localhost ~]# 

结果显示了配置文件的位置,如果没有找到,则需要找一个默认的配置文件复制一下。

拷贝配置文件

如果没有发现配置文件,则寻找mysql的位置:

1 [root@localhost ~]# whereis mysql
2 mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
3 [root@localhost ~]# 

然后进入 /usr/share/mysql 文件夹:

1 [root@localhost ~]# cd /usr/share/mysql
2 [root@localhost mysql]# 

找到默认的配置文件:

1 [root@localhost mysql]# find ./ -name '*.cnf'
2 ./my-default.cnf
3 [root@localhost mysql]# 

复制到默认的目录下并改名:

1 [root@localhost mysql]# cp my-default.cnf /etc/my.cnf
2 [root@localhost mysql]# 

配置文件就生成完毕了。

《MySQL入门——Linux下安装后的配置文件.doc》

下载本文的Word格式文档,以方便收藏与打印。