MySQL5.7版本有比较大的变化,在安装上也有不小区别,需要boost库,为了方便,我们直接安装自带boost的mysql(当然也可以先安装纯mysql,再单独安装boost库)。
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison
mkdir ~/src cd src wget https://dev.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.25.tar.gz
1、添加mysql用户
useradd -s /sbin/nologin mysql
2、创建mysql数据目录
mkdir -p /data/mysql/data chown -R mysql:mysql /data/mysql
3、安装
mkdir /usr/local/mysql tar -xzvf mysql-boost-5.7.25.tar.gz /usr/local/mysql cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_BOOST=boost make && make install
4、配置
vim /etc/my.cnf
根据自身实际需求修改配置项
[client] #password = your_password port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock datadir = /data/mysql/data default_storage_engine = InnoDB performance_schema_max_table_instances = 400 table_definition_cache = 400 skip-external-locking key_buffer_size = 32M max_allowed_packet = 100G table_open_cache = 128 sort_buffer_size = 768K net_buffer_length = 4K read_buffer_size = 768K read_rnd_buffer_size = 256K myisam_sort_buffer_size = 8M thread_cache_size = 16 query_cache_size = 16M tmp_table_size = 32M sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp = true #skip-name-resolve max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 log-bin=mysql-bin binlog_format=mixed server-id = 1 expire_logs_days = 10 slow_query_log=1 slow-query-log-file=/data/mysql/mysql-slow.log long_query_time=3 #log_queries_not_using_indexes=on early-plugin-load = "" innodb_data_home_dir = /data/mysql/data innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /data/mysql/data innodb_buffer_pool_size = 128M innodb_log_file_size = 64M innodb_log_buffer_size = 16M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 1 innodb_write_io_threads = 1 [mysqldump] quick max_allowed_packet = 500M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 32M sort_buffer_size = 768K read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
5、初始化
cd /usr/local/mysql/bin ./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
6、添加环境变量
#在 /etc/profile 新增一行 PATH=/usr/local/mysql/bin:$PATH
保存退出后让环境变量生效:
source /etc/profile
7、设置开机启动
ln -s /usr/local/mysql/bin/* /usr/local/bin/ cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld systemctl enable mysqld
8、启动mysql并设置root密码
systemctl start mysqld mysql -uroot -p #初始密码为空,所以直接回车
修改密码
set password='123456'