1.MySQL5.7安装注意事项
1.在MySQL5.7中mysql_install_db已经不再推荐使用,建议改成mysqld-initialize 完成实力初始化。(mysql_install_db在/mysql/bin目录下,同时取消了/mysql/scripts目录)
2.在初始化是如果加上--initial-insecure,则会创建空密码的root@localhost 账号,否则会创建带密码的root@localhost账号,密码直接写在log-error日志文件中
3.MySQL5.7的安装过程与5.6的主要区别在于数据初始化过程。
5.7.12二进制安装包下载地址:
链接:https://pan.baidu.com/s/1PAeHOyRRSMzRqCUIasE0xQ
密码:12r6
2.MySQL5.7安装
2.1 安装相关依赖包
大部分情况下生产环境在系统初始化的过程中已经安装大部分依赖包,防止偶然时间。
yum -y groupinstall "Development tools" yum -y install ncurses-devel openssl-devel bison gcc gcc-c++ make
2.2 解压MySQL二进制tar包
cd到mysql二进制的目录,然后使用tar命令解压
tar xf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
2.3 复制相关目录
复制解压后的mysql到mysqlbase目录
cp -rf mysql-5.7.12-linux-glibc2.5-x86_64 /usr/local/mysql
2.4 创建MySQL用户
在linux中添加mysql用户
useradd mysql
2.5 创建MySQL数据目录
创建数据目录
mkdir -p /home/mysql3306/mysql3306
创建日志目录
mkdir -p /home/mysql3306/logs
2.6 修改目录权限
修改数据目录、日志目录、base目录权限
chown -R mysql.mysql -R /home/mysql3306
chown -R mysql.mysql -R /usr/local/mysql/
2.7 创建配置文件
删掉系统自带my.cnf,创建自定义配置文件
mv /etc/my.cnf /etc/my.cnf.bak
vim /etc/my3306.cnf
my.cnf配置模板
#mysql5.7.9 [client] port = 3306 socket = /tmp/mysql3306.sock default_character_set = utf8mb4 [mysqld] # *** generic configuration options *** # lower_case_table_names = 1 port = 3306 basedir = /usr/local/mysql datadir = /home/mysql3306/mysql3306 socket = /tmp/mysql3306.sock pid_file = /home/mysql3306/mysql5711.pid tmpdir = /tmp/ slave_load_tmpdir = /tmp/ # *** dns resolve *** # skip_name_resolve = 1 external_locking explicit_defaults_for_timestamp = true character_set_client_handshake = FALSE character_set_server = utf8mb4 collation_server = utf8mb4_unicode_ci # *** connection *** # max_connections = 512 max_connect_errors = 100000 back_log = 102 interactive_timeout = 600 wait_timeout = 600 table_definition_cache = 5000 table_open_cache = 2048 #query_cache_size = 64M #query_cache_limit = 2M thread_cache_size = 51 ft_min_word_len = 4 #performance_schema = OFF ##If large data transfer problems,enlarge max_allowed_packet thread_stack = 192K # *** global memory parameter *** # max_allowed_packet = 16M tmp_table_size = 256M max_tmp_tables = 128 max_heap_table_size = 96M #close query cache #query_cache_type = 0 # *** session memory parameter *** # sort_buffer_size = 4M read_buffer_size = 4M #顺序IO join_buffer_size = 4M read_rnd_buffer_size = 8M #随机IO bulk_insert_buffer_size = 64M # # *** engine *** # default_storage_engine = InnoDB #ignore_builtin_innodb #plugin_load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so # *** log *** # log_timestamps = system log_bin = /home/mysql3306/logs/mysql-bin expire_logs_days = 10 binlog_format = mixed #binlog_gtid_simple_recovery = 1 #binlog_do_db #binlog_ignore_db log_slave_updates =1 relay_log = /home/mysql3306/logs/mysql5711_relay_bin relay_log_index = /home/mysql3306/logs/mysql5711_relay_bin.index relay_log_info_file = /home/mysql3306/logs/mysql5711_relay_bin.info relay_log_recovery = 0 log_error = /home/mysql3306/logs/mysql5711.err slow_query_log = 1 slow_query_log_file = /home/mysql3306/logs/mysql5711_slow.log long_query_time = 1 log_output = FILE log_queries_not_using_indexes = 1 log_slow_admin_statements = 1 log_slow_slave_statements = 1 log_throttle_queries_not_using_indexes = 10 min_examined_row_limit = 100 #general_log = off general_log_file = /home/mysql3306/logs/mysql5711_general.log #log_queries_not_using_indexes = /mysqllog/mysql5711/mysql5711_not_useing_index.log max_binlog_cache_size = 8M max_binlog_size = 1024M binlog_cache_size = 4M sync_binlog = 1 server_id = 15133306 #read_only = 0 #slave_skip_errors = all # *** MyISAM Specific options *** # #key_buffer_size = 128M #bulk_insert_buffer_size = 64M #myisam_sort_buffer_size = 128M #myisam_max_sort_file_size = 10G #myisam_repair_threads = 1 #myisam_recover_options = BACKUP,FORCE # *** INNODB Specific options *** # innodb_data_home_dir = /home/mysql3306/mysql3306/ innodb_data_file_path = ibdata1:1024M:autoextend innodb_log_group_home_dir = /home/mysql3306/mysql3306/ innodb_buffer_pool_instances = 1 innodb_buffer_pool_size = 1024MB innodb_buffer_pool_dump_pct = 40 innodb_page_cleaners = 4 innodb_log_file_size = 256M innodb_log_files_in_group = 2 innodb_log_buffer_size = 32M #default 16M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 30 innodb_undo_directory = /home/mysql3306/mysql3306/ innodb_undo_logs = 128 #must >=35.default 128 innodb_undo_tablespaces = 3 #must >=2 innodb_undo_log_truncate = 1 innodb_max_undo_log_size = 256M innodb_purge_rseg_truncate_frequency = 128 innodb_print_all_deadlocks = 1 innodb_sort_buffer_size = 64M #disabled_storage_engines =MyISAM innodb_buffer_pool_load_at_startup = 1 innodb_buffer_pool_dump_at_shutdown = 1 innodb_file_format_max =Antelope innodb_file_format =Antelope sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION" innodb_open_files = 4000 innodb_file_per_table = 1 innodb_status_file = 1 innodb_lock_wait_timeout = 30 innodb_read_io_threads = 8 innodb_write_io_threads = 8 innodb_io_capacity = 200 innodb_thread_concurrency = 32 innodb_commit_concurrency = 0 #innodb_flush_neighbors = 0 #for ssd #innodb_flush_neighbors = 1 #for other innodb_purge_batch_size = 1000 innodb_flush_log_at_trx_commit = 0 innodb_flush_method = O_DIRECT innodb_purge_threads = 4 #innodb_file_format = barracuda innodb_strict_mode = 1 innodb_support_xa = 1 skip_innodb_adaptive_hash_index innodb_force_recovery =0 #innodb_fast_shutdown innodb_change_buffering = all #innodb_use_native_aio = 1 innodb_max_dirty_pages_pct = 75 ##replication #replicate_do_db #replicate_ignore_db = mysql #replicate_ignore_db = test #replicate_do_table #replicate_ignore_table #replicate_wild_do_table #replicate_wild_ignore_table #gtid_mode = on #enforce_gtid_consistency = true master_info_repository = TABLE relay_log_info_repository = TABLE sync_master_info = 1 slave_parallel_workers = 2 binlog_checksum = CRC32 #default crc32 master_verify_checksum = 1 #default off slave_sql_verify_checksum = 1 #binlog_rows_query_log_events = 1 # ##semi sync replication settings #plugin_dir=/usr/local/mysql57/lib/plugin #plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" #loose_rpl_semi_sync_master_enabled = 1 #loose_rpl_semi_sync_slave_enabled = 1 #loose_rpl_semi_sync_master_timeout = 10000 # 10 second ##transaction transaction_isolation = REPEATABLE-READ #transaction_write_set_extraction= MURMUR32 #open --single-tra no use [mysqldump] quick max_allowed_packet = 16M [mysql] no_auto_rehash default_character_set = utf8mb4 [myisamchk] #key_buffer_size = 20M #sort_buffer_size = 4M #read_buffer = 4M #write_buffer = 2M [mysqlhotcopy] interactive_timeout [mysqld_safe] open_files_limit = 8192
2.8 初始化MySQL
MySQL5.7的初始化过程
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my3306.cnf --initialize-insecure --explicit_defaults_for_timestamp --basedir=/usr/local/mysql --datadir=/home/mysql3306/mysql3306/ --user=mysql
2.9 启动MySQL
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3306.cnf --datadir=/home/mysql3306/mysql3306/ --user=mysql &
查看进程和监听端口 ps -ef|grep mysql netstat -nltp|grep 3306
2.10 进入MySQL
启动后密码为空
/usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock
2.11 安装完成后,简单初始化权限
因为安装完成后,没有详细的权限设置,所以我们需要手动的配置一下简单的权限
delete from mysql.user where user!='root' or host!='localhost';
update mysql.user set authentication_string=password('root') where user='root';
*需要注意的是,在未来版本,MySQL将废弃此种授权方式
*MySQL5.7 mysql.user表没有password字段改 authentication_string;
grant all privileges on *.* to 'sys_admin'@'%' identified by '123456';
flush privileges;
*未来版本的授权方式
CREATE USER sysadmin@localhost IDENTIFIED BY '123456';
grant all privileges on *.* to sysadmin@localhost;
2.12 添加环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin/' >>/etc/profile source /etc/profile
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。