1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | create database name; 创建数据库use databasename; 选择数据库drop database name; 直接删除数据库,不提醒show tables; 显示表describe tablename; 表的详细描述select 中加上distinct去除重复字段显示当前mysql版本和当前日期select version(),current_date;修改mysql中root的密码:shell>mysql -u root -pmysql> update user set password=password(“root123″) where user=’root’;mysql> flush privileges 刷新权限mysql>use dbname; 打开数据库mysql>show databases; 显示所有数据库mysql>show tables; 显示数据库mysql中所有的表mysql>desc user; 显示表mysql数据库中user表的列信息) grant创建一个可以从任何地方连接到服务器的一个超管账户,必须分配一个密码mysql> grant all privileges on *.* to 'user_name'@'localhost' identified by 'password' ;格式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”删除授权:mysql> revoke all privileges on *.* from root@”%”;mysql> delete from user where user=”root” and host=”%”;mysql> flush privileges;重命名表:mysql > alter table t1 rename t2;备份:mysqldump -hhostname -uusername -ppassword databasename > backup.sql;恢复:mysql -hhostname -uusername -ppassword databasename< backup.sql; |
1 2 | /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql --defaults-file=/etc/my.cnf --user=mysql |
1 2 | /usr/local/mysql/bin/mysqld --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/ --initialize |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | [client]port = 3306socket = /tmp/mysql.sock#default-character-set=utf8 [mysql]#default-character-set=utf8[mysqld]port = 3306socket = /tmp/mysql.sockbasedir = /usr/local/mysqldatadir = /data/mysqlopen_files_limit = 3072back_log = 103max_connections = 512max_connect_errors = 100000table_open_cache = 512external-locking = FALSEmax_allowed_packet = 128Msort_buffer_size = 2Mjoin_buffer_size = 2Mthread_cache_size = 51query_cache_size = 32Mtmp_table_size = 96Mmax_heap_table_size = 96Mslow_query_log = 1slow_query_log_file = /data/mysql/slow.loglog-error = /data/mysql/error.loglong_query_time = 0.05server-id = 1323306log-bin = /data/mysql/mysql-binsync_binlog = 1binlog_cache_size = 4Mmax_binlog_cache_size = 128Mmax_binlog_size = 1024Mexpire_logs_days = 7key_buffer_size = 32Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mcharacter-set-server=utf8default-storage-engine=InnoDBbinlog_format=row#gtid_mode=on#log_slave_updates=1#enforce_gtid_consistency=1interactive_timeout=100wait_timeout=100transaction_isolation = REPEATABLE-READinnodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 1434Minnodb_data_file_path = ibdata1:1024M:autoextendinnodb_flush_log_at_trx_commit = 1innodb_log_buffer_size = 16Minnodb_log_file_size = 256Minnodb_log_files_in_group = 2innodb_max_dirty_pages_pct = 50innodb_file_per_table = 1innodb_locks_unsafe_for_binlog = 0[mysqldump]quickmax_allowed_packet = 32M |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | [client]port = 3306socket = /data/mysql/mysql.sock[mysql]prompt="\u@db \R:\m:\s [\d]> "no-auto-rehash[mysqld]user = mysqlport = 3306basedir = /usr/local/mysqldatadir = /data/mysql/socket = /data/mysql/mysql.sockcharacter-set-server = utf8mb4skip_name_resolve = 1open_files_limit = 65535back_log = 1024max_connections = 500max_connect_errors = 1000000table_open_cache = 1024table_definition_cache = 1024table_open_cache_instances = 64thread_stack = 512Kexternal-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 4Mjoin_buffer_size = 4Mthread_cache_size = 768query_cache_size = 0query_cache_type = 0interactive_timeout = 600wait_timeout = 600tmp_table_size = 32Mmax_heap_table_size = 32Mslow_query_log = 1slow_query_log_file = /data/mysql/slow.loglog-error = /data/mysql/error.loglong_query_time = 0.1server-id = 3306101log-bin = /data/mysql/mysql-binlogsync_binlog = 1binlog_cache_size = 4Mmax_binlog_cache_size = 1Gmax_binlog_size = 1Gexpire_logs_days = 7gtid_mode = onenforce_gtid_consistency = 1log_slave_updatesbinlog_format = rowrelay_log_recovery = 1relay-log-purge = 1key_buffer_size = 32Mread_buffer_size = 8Mread_rnd_buffer_size = 4Mbulk_insert_buffer_size = 64Mlock_wait_timeout = 3600explicit_defaults_for_timestamp = 1innodb_thread_concurrency = 0innodb_sync_spin_loops = 100innodb_spin_wait_delay = 30transaction_isolation = REPEATABLE-READinnodb_buffer_pool_size = 1024Minnodb_buffer_pool_instances = 8innodb_buffer_pool_load_at_startup = 1innodb_buffer_pool_dump_at_shutdown = 1innodb_data_file_path = ibdata1:1G:autoextendinnodb_flush_log_at_trx_commit = 1innodb_log_buffer_size = 32Minnodb_log_file_size = 2Ginnodb_log_files_in_group = 2innodb_max_undo_log_size = 4Ginnodb_io_capacity = 4000innodb_io_capacity_max = 8000innodb_flush_neighbors = 0innodb_write_io_threads = 8innodb_read_io_threads = 8innodb_purge_threads = 4innodb_page_cleaners = 4innodb_open_files = 65535innodb_max_dirty_pages_pct = 50innodb_flush_method = O_DIRECTinnodb_lru_scan_depth = 4000innodb_checksum_algorithm = crc32innodb_lock_wait_timeout = 10innodb_rollback_on_timeout = 1innodb_print_all_deadlocks = 1innodb_file_per_table = 1innodb_online_alter_log_max_size = 4Ginternal_tmp_disk_storage_engine = InnoDBinnodb_stats_on_metadata = 0innodb_status_file = 1innodb_status_output = 0innodb_status_output_locks = 0performance_schema = 1performance_schema_instrument = '%=on'[mysqldump]quickmax_allowed_packet = 32M |
1 2 3 4 5 6 7 8 9 10 | mysql> use test; Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> explain select * from sbtest;+----+-------------+--------+------+---------------+------+---------+------+-------+-------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+--------+------+---------------+------+---------+------+-------+-------+| 1 | SIMPLE | sbtest | ALL | NULL | NULL | NULL | NULL | 98712 | NULL | +----+-------------+--------+------+---------------+------+---------+------+-------+-------+ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@node3 ~]# mysql -uroot -proot123mysql> show variables like '%char%';+--------------------------+----------------------------------+| 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/local/mysql/share/charsets/ | +--------------------------+----------------------------------+8 rows in set (0.00 sec) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | --single-transaction用于保证innodb备份数据一致性,配合RR隔离级别使用;当发起事务,读取一个快照版本,直到备份结束时,都不会读取到本事务开始之后提交的数据;(很重要)-q, --quick加 SQL_NO_CACHE 标示符来确保不会读取缓存里的数据-l --lock-tables发起 READ LOCAL LOCK锁,该锁不会阻止读,也不会阻止新的数据插入--master-data两个值 1和2,如果值等于1,就会添加一个CHANGE MASTER语句(后期配置搭建主从架构)如果值等于2,就会在CHANGE MASTER语句前添加注释(后期配置搭建主从架构) -c, --complete-insert;导出完整sql语句-d,--no-data;不导出数据,只导表结构 -t,--no-create-info;只导数据,不导表结构 -w, --where=name ;按条件导出想要的数据 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 备份单个数据库或单个数据库中的指定表:mysqldump [OPTIONS] database [tb1] [tb2]…备份多个数据库:mysqldump [OPTIONS] –databases[OPTIONS] DB1 [DB2 DB3...]备份所有数据库:mysqldump [OPTIONS] –all-databases[OPTIONS]利用mysql命令恢复数据:mysql -uroot -proot23 db_name < table_name.sqlxtrabackup备份原理分析:对于Innodb,它是基于Innodb的crash recovery功能进行备份。 |
1 2 3 4 5 | 首先需要创建备份目录:/opt/data/innobackupex --no-timestamp --defaults-file=/etc/my.cnf --user root --socket=/tmp/mysql.sock --password root123 /opt/data/all-20170719-bak注--no-timestamp 该参数的含义:不需要系统创建时间目录,自己可以命名; |
1 2 3 4 5 6 | [root@node3 all-20170720-incr]# cat xtrabackup_checkpoints backup_type = incrementalfrom_lsn = 267719862to_lsn = 267720940last_lsn = 267720940compact = 0 |
1 2 3 4 5 6 | [root@node3 all-20170721-incr2]# cat xtrabackup_checkpointsbackup_type = incrementalfrom_lsn = 267720940to_lsn = 267721260last_lsn = 267721260compact = 0 |
1 2 3 | ./innobackupex --no-timestamp --user root --socket=/tmp/mysql.sock --password root123 --defaults-file=/etc/my.cnf --incremental --incremental-basedir=/opt/data/all-20170719-bak /data/xtrabackup/all-20170720-incr |
1 2 3 | ./innobackupex --no-timestamp --user root --socket=/tmp/mysql.sock --password root123 --defaults-file=/etc/my.cnf --incremental --incremental-basedir=/data/xtrabackup/all-20170720-incr /data/xtrabackup/all-20170721-incr2 |
1 2 3 4 5 6 7 8 | innobackupex --user root --socket=/tmp/mysql.sock --password root123 --defaults-file=/etc/my.cnf --apply-log --redo-only +全备innobackupex --user root --socket=/tmp/mysql.sock --password root123 --defaults-file=/etc/my.cnf --apply-log --redo-only 全备 --incremental-dir=增备1innobackupex --user root --socket=/tmp/mysql.sock --password root123 --defaults-file=/etc/my.cnf --apply-log --redo-only 全备 --incremental-dir=增备2innobackupex --user root --socket=/tmp/mysql.sock --password root123 --defaults-file=/etc/my.cnf --apply-log +全备 |
本文出自 “张甦的博客” 博客








