一、理论:
1.错误日志:
a.记录了mysqld启动和停止时以及出错时的相关信息,当数据库出现故障导致无法启动时可以先查看此信息。
b.可用--log-error来指定mysqld保存错误日志文件的位置
2.二进制日志:
a.statement:记录的都是语句。优点:日志记录清晰易读、日志量少、对I/O影响较小,缺点:在某些情况下slave的日志复制会出错
b.row:将每一行的变更记录到日志中,而不是记录sql语句。优点:记录每一行的数据变化细节,不会出现某些情况下无法复制的情况,缺点:日志量大,对I/O影响较大
c.mixed:目前mysql的默认日志格式。尽可能对上两种模式的优点加以利用而避开它们的缺点
d.可以在global和session级别对binlog_format进行日志格式的操作,确保从库的复制能够正常进行
3.日志的读取:
a.mysqlbinlog工具
4.日志的删除:
a.reset master.可以删除所有的binlog日志
b.purge master logs to 'mysql-bin.*',将删除*编号前的所有日志
c.purge master logs before 'yyyy-mm-dd hh24:mi:ss',将删除日期为指定日期之前的所有日志
d.--expire_logs_days=#:设置日志的过期天数
5.其他选项:
a.--binlog-do-db=db_name:仅更新db_name数据库记录到二进制日志中而不更新其他数据库
b.--binlog-ignore-db=db_name:忽略db_name数据库记录到二进制日志中
c.--innodb-safe-binlog:与--sync-binlog=N(每写N次日志同步磁盘)一起配合使用,使得事务在日志中的记录更加安全
d.sql_log_bin=0:具有super权限的客户端可以通过设置此值使得禁止将自己的操作写入二进制记录。但有可能会导致主从数据不一致
6.日志的读取:查询日志记录的格式是纯文本,所以可以直接进行读取
7.慢查询日志:
a.记录了所有时间超过long_query_time的设置值并且扫描记录数不小于in_examined_row_limit的所有sql语句的日志
b.默认情况下,管理语句和不使用索引进行查询的语句不会记录到慢查询日志
c.--slow_query_log指定慢查询的状态,--show_query_log_file指定慢查询输出的路径,--log-out指定输出慢查询的方式(输出到表则只能精确到秒,输出到文件则能精确到微秒)
8.日志的读取:
a.查询long_query_time的值:show variables like 'long%';
b.set long_query_time:设置long_query_time的值
c.more localhost-slow.log:查看慢查询日志的值
9.其他查看日志的相关工具:
a.mysqlsla:查看日志
b.sqlprofi,mysql-expain-slow-log,mysqllogfilter:分析日志
二、实践:
mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> create table emp( -> id int(11), -> info varchar(20) -> ) engine = innnodb charset = utf8; Query OK, 0 rows affected, 2 warnings (0.05 sec) mysql> insert into emp values(1,'z1'); Query OK, 1 row affected (0.00 sec) mysql> insert into emp values(1,'z2'); Query OK, 1 row affected (0.00 sec) mysql> exit abc@ubuntu:~/Downloads/mysql$ mysql -uroot -p123 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 98 Server version: 5.5.44-log Source distribution Copyright (c) 2000, 2015, 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> show global variables like '%log%'; +-----------------------------------------+---------------------------------------+ | Variable_name | Value | +-----------------------------------------+---------------------------------------+ | back_log | 50 | | binlog_cache_size | 32768 | | binlog_direct_non_transactional_updates | OFF | | binlog_format | STATEMENT | | binlog_stmt_cache_size | 32768 | | expire_logs_days | 14 | | general_log | OFF | | general_log_file | /usr/local/mysql/data/ubuntu.log | | innodb_flush_log_at_trx_commit | 2 | | innodb_locks_unsafe_for_binlog | OFF | | innodb_log_buffer_size | 8388608 | | innodb_log_file_size | 67108864 | | innodb_log_files_in_group | 2 | | innodb_log_group_home_dir | ./ | | innodb_mirrored_log_groups | 1 | | log | OFF | | log_bin | ON | | log_bin_trust_function_creators | OFF | | log_error | /usr/local/mysql/data/mysql-error.log | | log_output | FILE | | log_queries_not_using_indexes | ON | | log_slave_updates | OFF | | log_slow_queries | ON | | log_warnings | 1 | | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | | max_relay_log_size | 0 | | relay_log | | | relay_log_index | | | relay_log_info_file | relay-log.info | | relay_log_purge | ON | | relay_log_recovery | OFF | | relay_log_space_limit | 0 | | slow_query_log | ON | | slow_query_log_file | /usr/local/mysql/data/mysql-slow.log | | sql_log_bin | ON | | sql_log_off | OFF | | sync_binlog | 1 | | sync_relay_log | 0 | | sync_relay_log_info | 0 | +-----------------------------------------+---------------------------------------+ 41 rows in set (0.02 sec) -> Ctrl-C -- exit! Aborted abc@ubuntu:~/Downloads/mysql$ mysqld --verbose --help | grep -A 1 'Default options' 151106 15:37:14 [Warning] option 'table_definition_cache': unsigned value 100 adjusted to 400 151106 15:37:14 [Note] mysqld (mysqld 5.5.44-log) starting as process 76330 ... 151106 15:37:14 [Warning] Can't create test file /usr/local/mysql/data/ubuntu.lower-test 151106 15:37:14 [Warning] Can't create test file /usr/local/mysql/data/ubuntu.lower-test 151106 15:37:14 [Warning] One can only use the --user switch if running as root mysqld: File '/usr/local/mysql/data/mysql-bin.index' not found (Errcode: 13) Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 151106 15:37:14 [ERROR] Aborting abc@ubuntu:~/Downloads/mysql$ mysqld --verbose --help | grep -A 1 'Default options' 151106 15:37:32 [Warning] option 'table_definition_cache': unsigned value 100 adjusted to 400 151106 15:37:32 [Note] mysqld (mysqld 5.5.44-log) starting as process 76335 ... 151106 15:37:32 [Warning] Can't create test file /usr/local/mysql/data/ubuntu.lower-test 151106 15:37:32 [Warning] Can't create test file /usr/local/mysql/data/ubuntu.lower-test 151106 15:37:32 [Warning] One can only use the --user switch if running as root mysqld: File '/usr/local/mysql/data/mysql-bin.index' not found (Errcode: 13) Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 151106 15:37:32 [ERROR] Aborting //以下文件就是mysql的本机上的配置文件 abc@ubuntu:~/Downloads/mysql$ vi /usr/local/mysql/etc/my.cnf mysql> select count(*) from payment p left join customer c on p.payment_id = c.customer_id; +----------+ | count(*) | +----------+ | 16049 | +----------+ 1 row in set (0.06 sec) mysql> show variables like 'long%'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 2.000000 | +-----------------+----------+ 1 row in set (0.00 sec) mysql> set long_query_time = 0.05; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'long%'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 0.050000 | +-----------------+----------+ 1 row in set (0.00 sec) mysql> select count(*) from payment p left join customer c on p.payment_id = c.customer_id order by c.customer_id; +----------+ | count(*) | +----------+ | 16049 | +----------+ 1 row in set (0.07 sec) mysql> Ctrl-C -- exit! Aborted abc@ubuntu:/usr/local/mysql/data$ sudo tail ./mysql-slow.log [sudo] password for abc: # Time: 151106 23:40:39 # User@Host: root[root] @ localhost [] # Query_time: 0.047216 Lock_time: 0.000099 Rows_sent: 1 Rows_examined: 16650 SET timestamp=1446882039; select count(*) from payment p left join customer c on p.payment_id = c.customer_id; # Time: 151106 23:41:02 # User@Host: root[root] @ localhost [] # Query_time: 0.075027 Lock_time: 0.000083 Rows_sent: 1 Rows_examined: 32699 SET timestamp=1446882062; select count(*) from payment p left join customer c on p.payment_id = c.customer_id order by c.customer_id;

MySQL은 초보자가 데이터베이스 기술을 배우는 데 적합합니다. 1. MySQL 서버 및 클라이언트 도구를 설치하십시오. 2. SELECT와 같은 기본 SQL 쿼리를 이해하십시오. 3. 마스터 데이터 작업 : 데이터를 만들고, 삽입, 업데이트 및 삭제합니다. 4. 고급 기술 배우기 : 하위 쿼리 및 창 함수. 5. 디버깅 및 최적화 : 구문 확인, 인덱스 사용, 선택*을 피하고 제한을 사용하십시오.

MySQL은 테이블 구조 및 SQL 쿼리를 통해 구조화 된 데이터를 효율적으로 관리하고 외래 키를 통해 테이블 간 관계를 구현합니다. 1. 테이블을 만들 때 데이터 형식을 정의하고 입력하십시오. 2. 외래 키를 사용하여 테이블 간의 관계를 설정하십시오. 3. 인덱싱 및 쿼리 최적화를 통해 성능을 향상시킵니다. 4. 데이터 보안 및 성능 최적화를 보장하기 위해 데이터베이스를 정기적으로 백업 및 모니터링합니다.

MySQL은 웹 개발에 널리 사용되는 오픈 소스 관계형 데이터베이스 관리 시스템입니다. 주요 기능에는 다음이 포함됩니다. 1. 다른 시나리오에 적합한 InnoDB 및 MyISAM과 같은 여러 스토리지 엔진을 지원합니다. 2.로드 밸런싱 및 데이터 백업을 용이하게하기 위해 마스터 슬레이브 복제 기능을 제공합니다. 3. 쿼리 최적화 및 색인 사용을 통해 쿼리 효율성을 향상시킵니다.

SQL은 MySQL 데이터베이스와 상호 작용하여 데이터 첨가, 삭제, 수정, 검사 및 데이터베이스 설계를 실현하는 데 사용됩니다. 1) SQL은 Select, Insert, Update, Delete 문을 통해 데이터 작업을 수행합니다. 2) 데이터베이스 설계 및 관리에 대한 생성, 변경, 삭제 문을 사용하십시오. 3) 복잡한 쿼리 및 데이터 분석은 SQL을 통해 구현되어 비즈니스 의사 결정 효율성을 향상시킵니다.

MySQL의 기본 작업에는 데이터베이스, 테이블 작성 및 SQL을 사용하여 데이터에서 CRUD 작업을 수행하는 것이 포함됩니다. 1. 데이터베이스 생성 : createAbasemy_first_db; 2. 테이블 만들기 : CreateTableBooks (idintauto_incrementprimarykey, titlevarchar (100) notnull, authorvarchar (100) notnull, published_yearint); 3. 데이터 삽입 : InsertIntobooks (Title, Author, Published_year) VA

웹 응용 프로그램에서 MySQL의 주요 역할은 데이터를 저장하고 관리하는 것입니다. 1. MySQL은 사용자 정보, 제품 카탈로그, 트랜잭션 레코드 및 기타 데이터를 효율적으로 처리합니다. 2. SQL 쿼리를 통해 개발자는 데이터베이스에서 정보를 추출하여 동적 컨텐츠를 생성 할 수 있습니다. 3.mysql은 클라이언트-서버 모델을 기반으로 작동하여 허용 가능한 쿼리 속도를 보장합니다.

MySQL 데이터베이스를 구축하는 단계에는 다음이 포함됩니다. 1. 데이터베이스 및 테이블 작성, 2. 데이터 삽입 및 3. 쿼리를 수행하십시오. 먼저 CreateAbase 및 CreateTable 문을 사용하여 데이터베이스 및 테이블을 작성한 다음 InsertInto 문을 사용하여 데이터를 삽입 한 다음 최종적으로 SELECT 문을 사용하여 데이터를 쿼리하십시오.

MySQL은 사용하기 쉽고 강력하기 때문에 초보자에게 적합합니다. 1.MySQL은 관계형 데이터베이스이며 CRUD 작업에 SQL을 사용합니다. 2. 설치가 간단하고 루트 사용자 비밀번호를 구성해야합니다. 3. 삽입, 업데이트, 삭제 및 선택하여 데이터 작업을 수행하십시오. 4. Orderby, Where and Join은 복잡한 쿼리에 사용될 수 있습니다. 5. 디버깅은 구문을 확인하고 쿼리를 분석하기 위해 설명을 사용해야합니다. 6. 최적화 제안에는 인덱스 사용, 올바른 데이터 유형 선택 및 우수한 프로그래밍 습관이 포함됩니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

Dreamweaver Mac版
시각적 웹 개발 도구

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구
