centos7:
yum -y install gcc gcc-devel gcc-c++ gcc-c++-devel autoconf* automake* zlib* libxml*ncurses-devel ncurses libgcrypt* libtool* cmake openssl openssl-devel bisonbison-devel perl-Data-Dumper boost boost-doc boost-devel ncurses-devel
#cp配置文件
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/mysql/bin/* /usr/bin/
chmod 755 /etc/init.d/mysqld
初始化配置安装:
cd /usr/local/mysql/bin
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
mkdir /data/mysql/log && chown -R mysql:mysql /data/mysql
配置文件 my.cnf
[client]
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
binlog_format = mixed
port = 3306
socket = /data/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
log-bin = mysql1-bin
server-id = 5
binlog-ignore-db = mysql
binlog-ignore-db = information_schema
binlog-ignore-db = sys
binlog-ignore-db = performance_schema
auto-increment-increment = 5
auto-increment-offset = 1
log-slave-updates = ON
max_connections=3000
log_timestamps=SYSTEM
back_log=50
max_user_connections=2000
innodb_thread_concurrency=8
default-storage-engine=InnoDB
innodb_buffer_pool_size=8192M
innodb_log_buffer_size=8M
innodb_log_file_size=48M
innodb_flush_log_at_trx_commit=2
innodb_lock_wait_timeout=50
long_query_time = 1
slow_query_log=YES
slow_query_log_file=/data/mysql/log/slow.log
log-error=/data/mysql/log/error.log
plugin-load=AUDIT=libaudit_plugin.so
audit_json_file=1
audit_json_file=ON
audit_record_cmds=connect,Quit,show,select,insert,update,delete
audit_whitelist_users=admintool,blacklist,blackselect,procdb,mysql1,gmetric,mysql.sys,{}
命令行下具体用法如下:
mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名;
mysql -u用戶名 -p密码 数据库名 < 脚本名
导出整个数据库结构和数据
mysqldump -h localhost -uroot -p123456 database > dump.sql
导出单个数据表结构和数据
mysqldump -h localhost -uroot -p123456 database table > dump.sql
导出整个数据库结构(不包含数据)
mysqldump -h localhost -uroot -p123456 -d database > dump.sql
导出单个数据表结构(不包含数据)
mysqldump -h localhost -uroot -p123456 -d database table > dump.sql
导出存储过程
mysqldump -u 数据库用户名 -p -n -t -d -R 数据库名 > 文件名 。再导入时如果报错ERROR 1235 (42000) at line **: This version of MySQL doesn't yet support ‘multiple triggers with the same action time and event for one table’,需要把trigger关闭
mysqldump -u 数据库用户名 -p -n -t -d -R --triggers=false 数据库名 > 文件名 。 如果报错ErrorCode:1418This function has none of DETERMINISTIC, NOSQL, or READS SQL DATA inits declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
解决方法是,在/etc/my.cnf中找到[mysqld],在它下面添加这样一行:log-bin-trust-function-creators=1
清理十天之前的binlog:PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY);
清除MySQL-bin.010日志:PURGE MASTER LOGS TO 'MySQL-bin.010';