MySQL的参数文件为----my.cnf
- 如何确定数据库读取的哪一个,命令给出了答案
[[email protected] home]# mysql --help |grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
[[email protected] home]# - 参数有的是为客户端准备,有的是为服务器准备
[[email protected] home]# cat /etc/my.cnf | grep -v "^#"
[client]
port=3306
[mysqld]
datadir=/opt/mysql/databasedir = /usr/local/mysql
socket=/usr/local/mysql/mysql.sock
user=mysql
character_set_server=utf8
server_id = 12
join_buffer_size = 128M
sort_buffer_size = 2M
pid-file=/opt/mysql/data/mysqld.pid
[[email protected] home]# - 什么是参数?
这个就好比是键跟值得关系 如read_buffer_size=12M read_buffer_size就是键 12M就是指
分为两类动态和静态的(只读),也可以分成是全局和局部的,动态的可以修改但是只会在mysql server的整个生命周期中起作用,下次重启之后会重新根据参数配置文件加载,所以要想永久生效还是修改配置文件,局部只对当前session有效,全局的对所有重新上来的会话有效,动态修改参数使用set [global] variables=key。
- 查看参数
可以使用show variables like "variables_name" select @@session.variables_name select @@global.variables_name
如查看read_buffer_size
mysql> set read_buffer_size=524288;
Query OK, 0 rows affected (0.07 sec)mysql> select @@session.read_buffer_size;
+----------------------------+
| @@session.read_buffer_size |
+----------------------------+
| 524288 |
+----------------------------+
1 row in set (0.00 sec)mysql> select @@global.read_buffer_size;
+---------------------------+
| @@global.read_buffer_size |
+---------------------------+
| 131072 |
+---------------------------+
1 row in set (0.00 sec)mysql> show variables like "read_buffer_size%";
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 524288 |
+------------------+--------+
1 row in set (0.00 sec)可以看到同样设置了read_buffer_size但是session和global却不一样 因为我设置的时候没有加global
- 如果更改静态参数会有什么结果呢
mysql> set global datadir=‘/opt‘;
ERROR 1238 (HY000): Variable ‘datadir‘ is a read only variable
mysql>