源码包安装Mysql
前期准备
mkdir /usr/local/src/mysql5.7.10-glibc cd /usr/local/src/mysql5.7.10-glibc
#下载mysql包 wget https://mirrors.aliyun.com/mysql/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
#vim my.cnf [client] port = 3306 socket = /tmp/mysql.sock [mysqld] lower_case_table_names = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES character_set_server=utf8 port = 3306 socket = /tmp/mysql.sock datadir = /home/mysqldata ft_min_word_len = 1 slow_query_log = 1 slow_query_log_file = /home/mysqldata/mysqlslow.log long_query_time = 1 skip-external-locking back_log = 600 max_connections = 3000 max_connect_errors = 1000000 table_open_cache = 1024 max_allowed_packet = 32M binlog_cache_size = 4M max_heap_table_size = 256M read_buffer_size = 2M read_rnd_buffer_size = 8M sort_buffer_size = 16M join_buffer_size = 16M thread_cache_size = 300 query_cache_type = Off query_cache_size = 0 query_cache_limit = 8M ft_min_word_len = 8 default-storage-engine = INNODB thread_stack = 192K transaction_isolation = REPEATABLE-READ tmp_table_size = 256M sync_binlog = 0 expire_logs_days = 5 binlog_format=mixed key_buffer_size = 32M bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 5G myisam_repair_threads = 1 log_timestamps=SYSTEM local-infile=0 #replication server_id=1 binlog-ignore-db=mysql log-bin=/home/mysqlbinloginfo/master-mysql-bin max_binlog_size = 100M max_binlog_cache_size = 2G innodb_buffer_pool_size = 4G innodb_data_file_path = ibdata1:10M:autoextend innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 16M innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 innodb_file_per_table = On [mysqldump] quick max_allowed_packet = 16M [mysql] auto-rehash [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] open-files-limit = 8192
开始安装
关闭防火墙
systemctl stop firewalld setenforce 0
创建用户
groupadd mysql && useradd -M -g mysql -s /sbin/nologin mysql
安装依赖
yum install -y libaio.x86_64
删除已存在文件
mv /etc/my.cnf /etc/my.cnf.bak
创建数据存放文件夹
mkdir /home/mysqldata && mkdir /home/mysqlbinloginfo
拷贝文件
cd /usr/local/src/mysql5.7.10-glibc && cp -f /usr/local/src/mysql5.7.10-glibc/my.cnf /etc/my.cnf
解压
tar -xvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz -C /usr/local && mv /usr/local/mysql-5.7.10-linux-glibc2.5-x86_64 /usr/local/mysql
授权文件权限
chown -R mysql:mysql /usr/local/mysql/* /home/mysqldata /home/mysqlbinloginfo && chmod -R 755 /home/mysqldata
安装
cd /usr/local/mysql/bin && ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysqldata
拷贝启动文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && sed -i '47 c\datadir=/home/mysqldata' /etc/init.d/mysqld
添加环境变量
echo -e "export PATH=/usr/local/mysql/bin:\$PATH" > /etc/profile.d/mysql.sh
设置自启
chkconfig --add mysqld && chkconfig mysqld on && systemctl start mysqld
查看初始密码
mima=`cat /root/.mysql_secret | sed -n '2p'`
设置新密码
mysqlpw=*hy7uBHf6
生效系统文件
source /etc/profile
修改初始密码(按要求必须修改初始密码)
mysql -uroot -p$mima --connect-expired-password -e "alter user 'root'@'localhost' identified by '${mysqlpw}';flush privileges;"