配置mysql命令_Mysql 数据库常用配置命令

1.查看mysql数据库默认编码:

mysql> show variables like "character%";

+--------------------------+----------------------------+

| Variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

8 rows in set (0.00 sec)

2.开启Mysql数据库慢查询和binlog日志功能

1)开启慢查询日志,找到my.cnf,添加如下内容 vim /usr/local/mysql/my.cnf

b6c58d822edc9fc53c9032378c33ebfd.png

然后重启mysql服务:systemctl restart mysqld

查看慢查询日志是否开启:

mysql> show variables like 'slow_query_log';

+----------------+-------+

| Variable_name | Value |

+----------------+-------+

| slow_query_log | ON |

+----------------+-------+

1 row in set (0.03 sec)

mysql> show variables like '%quer%';

+----------------------------------------+---------------------+

| Variable_name | Value |

+----------------------------------------+---------------------+

| binlog_rows_query_log_events | OFF |

| ft_query_expansion_limit | 20 |

| have_query_cache | YES |

| log_queries_not_using_indexes | ON |

| log_throttle_queries_not_using_indexes | 0 |

| long_query_time | 1.000000 |

| query_alloc_block_size | 8192 |

| query_cache_limit | 1048576 |

| query_cache_min_res_unit | 4096 |

| query_cache_size | 1048576 |

| query_cache_type | OFF |

| query_cache_wlock_invalidate | OFF |

| query_prealloc_size | 8192 |

| slow_query_log | ON |

| slow_query_log_file | /tmp/mysql-slow.log |

+----------------------------------------+---------------------+

15 rows in set (0.00 sec)

如上所示:已经开启了慢查询日志!

注意:如果更改日志目录位置

比如,更改为/home/msyql/log/mysql-slow.log

至少需要将log目录所有者设置为mysql:mysql。

这样重启mysql的时候,才能自动生成mysql-slow.log文件。

如果log目录不是mysql用户权限,将无法生成日志文件,mysql用户无权写入数据。

2)bin-log日志开启, 必须设置server-id.

6da90f0b9466b7448fb32af9a377af50.png

保存退出,重启mysql服务:systemctl restart mysqld

查看 logbin是否开启:

mysql> show variables like "%log_bin%";

+---------------------------------+--------------------------------+

| Variable_name | Value |

+---------------------------------+--------------------------------+

| log_bin | ON |

| log_bin_basename | /var/lib/mysql/mysql-bin |

| log_bin_index | /var/lib/mysql/mysql-bin.index |

| log_bin_trust_function_creators | OFF |

| log_bin_use_v1_row_events | OFF |

| sql_log_bin | ON |

+---------------------------------+--------------------------------+

6 rows in set (0.01 sec)

如上所示binlog已经开启!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值